/* ==========================================================================
   Aviation Accounting System — Reusable Components
   Cards, KPIs, Buttons, Tables, Badges, Alerts, Forms, Tabs, Pagination,
   Modals, Toasts, Tooltips, Empty States, Loading, Progress, Tags, Avatars,
   Dividers, Timelines
   ========================================================================== */

/* ==========================================================================
   1. Cards
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

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

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.card-body {
  padding: 20px;
}

.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--background);
}

/* ==========================================================================
   2. KPI Cards
   ========================================================================== */

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.kpi-icon.blue {
  background: #eff6ff;
  color: #2563eb;
}

.kpi-icon.green {
  background: #f0fdf4;
  color: #16a34a;
}

.kpi-icon.amber {
  background: #fffbeb;
  color: #d97706;
}

.kpi-icon.red {
  background: #fef2f2;
  color: #dc2626;
}

.kpi-icon.purple {
  background: #faf5ff;
  color: #9333ea;
}

.kpi-icon.cyan {
  background: #ecfeff;
  color: #0891b2;
}

.kpi-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.kpi-change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
}

.kpi-change.positive {
  color: var(--success);
}

.kpi-change.negative {
  color: var(--danger);
}

.kpi-compare {
  font-size: 12px;
  color: var(--text-muted);
}

/* ==========================================================================
   3. Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  line-height: 1.4;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--background);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-success {
  background: var(--success);
  color: #ffffff;
}

.btn-success:hover {
  opacity: 0.9;
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-danger:hover {
  opacity: 0.9;
}

.btn-warning {
  background: var(--warning);
  color: #ffffff;
}

.btn-warning:hover {
  opacity: 0.9;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--background);
}

.btn-link {
  background: transparent;
  color: var(--primary);
  padding: 0;
}

.btn-link:hover {
  text-decoration: underline;
}

/* Button Sizes */

.btn-xs {
  padding: 4px 8px;
  font-size: 12px;
}

.btn-sm {
  padding: 6px 12px;
}

.btn-lg {
  padding: 10px 24px;
  font-size: 15px;
}

/* Icon Only Button */

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
}

/* Button States */

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-loading {
  opacity: 0.7;
  cursor: wait;
  pointer-events: none;
}

.btn-loading .btn-text {
  opacity: 0;
}

.btn-spinner {
  border: 2px solid;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  width: 16px;
  height: 16px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
   4. Tables
   ========================================================================== */

.table-container {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table thead {
  background: var(--background);
  position: sticky;
  top: 0;
}

.table th {
  padding: 10px 16px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: start;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

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

.table tbody tr {
  transition: background 0.1s ease;
}

.table tbody tr:hover {
  background: #f8fafc;
}

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

/* Compact Table */

.table-compact th,
.table-compact td {
  padding: 8px 12px;
}

/* Financial Amounts */

.text-end {
  text-align: end;
  font-variant-numeric: tabular-nums;
}

.amount-negative {
  color: var(--danger);
}

.amount-positive {
  color: var(--success);
}

/* Sticky First Column */

.table .sticky-col {
  position: sticky;
  inset-inline-start: 0;
  background: var(--surface);
  z-index: 1;
}

/* ==========================================================================
   5. Status Badges
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-default {
  background: #f1f5f9;
  color: #475569;
}

.badge-success {
  background: #f0fdf4;
  color: #15803d;
}

.badge-warning {
  background: #fffbeb;
  color: #b45309;
}

.badge-danger {
  background: #fef2f2;
  color: #b91c1c;
}

.badge-info {
  background: #eff6ff;
  color: #1d4ed8;
}

.badge-primary {
  background: #eff6ff;
  color: #1e40af;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ==========================================================================
   6. Alerts
   ========================================================================== */

.alert {
  padding: 14px 18px;
  border-radius: 10px;
  border: 1px solid;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 13px;
}

.alert-info {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

.alert-success {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #166534;
}

.alert-warning {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

.alert-danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.alert-icon {
  flex-shrink: 0;
  font-size: 18px;
}

.alert-content {
  flex: 1;
}

.alert-close {
  flex-shrink: 0;
  cursor: pointer;
  opacity: 0.5;
}

.alert-close:hover {
  opacity: 1;
}

/* ==========================================================================
   7. Forms
   ========================================================================== */

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-label .required {
  color: var(--danger);
  margin-inline-start: 2px;
}

.form-control {
  width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 43, 76, 0.08);
  outline: none;
}

.form-control.is-invalid {
  border-color: var(--danger);
}

.form-help {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 4px;
}

/* Input with Icon */

.input-icon {
  position: relative;
}

.input-icon .form-control {
  padding-inline-start: 38px;
}

.input-icon .input-icon-el {
  position: absolute;
  inset-inline-start: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: 15px;
}

/* Select */

.form-select {
  width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--surface);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: inset-inline-end 12px center;
  padding-inline-end: 36px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  cursor: pointer;
}

.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 43, 76, 0.08);
  outline: none;
}

.form-select.is-invalid {
  border-color: var(--danger);
}

/* Textarea */

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

/* Checkbox & Radio */

.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Switch / Toggle */

.form-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.form-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.form-switch .switch-track {
  width: 40px;
  height: 22px;
  background: var(--border);
  border-radius: 11px;
  transition: background 0.2s ease;
  position: relative;
}

.form-switch .switch-thumb {
  position: absolute;
  top: 2px;
  inset-inline-start: 2px;
  width: 18px;
  height: 18px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: inset-inline-start 0.2s ease;
}

.form-switch input:checked + .switch-track {
  background: var(--primary);
}

.form-switch input:checked + .switch-track .switch-thumb {
  inset-inline-start: 20px;
}

/* ==========================================================================
   8. Tabs
   ========================================================================== */

.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
}

.tab-item {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s ease;
}

.tab-item:hover {
  color: var(--text-primary);
}

.tab-item.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content {
  padding: 20px 0;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ==========================================================================
   9. Pagination
   ========================================================================== */

.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-item {
  min-width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.page-item:hover {
  background: var(--background);
}

.page-item.active {
  background: var(--primary);
  color: #ffffff;
}

.page-item.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.pagination-info {
  font-size: 13px;
  color: var(--text-secondary);
  margin-inline-end: 12px;
}

/* ==========================================================================
   10. Modals
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-xl);
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.95) translateY(10px);
  transition: transform 0.2s ease;
}

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

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

.modal-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
}

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

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding-block: 16px;
  padding-inline: 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

body.modal-open {
  overflow: hidden;
}

/* ==========================================================================
   11. Toast Notifications
   ========================================================================== */

.toast-container {
  position: fixed;
  top: 20px;
  inset-inline-end: 20px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  min-width: 320px;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 14px 18px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transform: translateX(calc(100% + 20px));
  opacity: 0;
  transition: all 0.3s ease;
}

[dir="rtl"] .toast {
  transform: translateX(calc(-100% - 20px));
}

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

.toast.leaving {
  transform: translateX(calc(100% + 20px));
  opacity: 0;
}

[dir="rtl"] .toast.leaving {
  transform: translateX(calc(-100% - 20px));
}

.toast-icon {
  font-size: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.toast-content {
  flex: 1;
  min-width: 0;
}

.toast-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.toast-message {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.toast-close {
  flex-shrink: 0;
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.15s ease;
}

.toast-close:hover {
  opacity: 1;
}

/* Toast Variants */

.toast-success {
  border-inline-start: 3px solid var(--success);
}

.toast-danger {
  border-inline-start: 3px solid var(--danger);
}

.toast-warning {
  border-inline-start: 3px solid var(--warning);
}

.toast-info {
  border-inline-start: 3px solid var(--primary);
}

/* ==========================================================================
   12. Tooltip
   ========================================================================== */

.tooltip {
  position: relative;
}

.tooltip-text {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #ffffff;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: all 0.15s ease;
  z-index: 100;
}

.tooltip-text::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: #1e293b;
}

.tooltip:hover .tooltip-text,
.tooltip[data-tooltip-visible] .tooltip-text {
  opacity: 1;
  visibility: visible;
}

/* ==========================================================================
   13. Empty State
   ========================================================================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
}

.empty-icon {
  font-size: 48px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.empty-desc {
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 360px;
}

/* ==========================================================================
   14. Loading States
   ========================================================================== */

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.loading-spinner.sm {
  width: 16px;
  height: 16px;
}

.loading-spinner.lg {
  width: 36px;
  height: 36px;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: inherit;
}

/* ==========================================================================
   15. Progress Bar
   ========================================================================== */

.progress {
  height: 6px;
  background: var(--background);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-bar.primary {
  background: var(--primary);
}

.progress-bar.success {
  background: var(--success);
}

.progress-bar.warning {
  background: var(--warning);
}

.progress-bar.danger {
  background: var(--danger);
}

/* ==========================================================================
   16. Tags / Chips
   ========================================================================== */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  background: var(--background);
  color: var(--text-secondary);
}

.tag-remove {
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s ease;
  line-height: 1;
}

.tag-remove:hover {
  opacity: 1;
}

/* ==========================================================================
   17. Avatar Group
   ========================================================================== */

.avatar-group {
  display: flex;
}

.avatar-group .avatar {
  border: 2px solid #ffffff;
  margin-inline-start: -8px;
}

.avatar-group .avatar:first-child {
  margin-inline-start: 0;
}

/* ==========================================================================
   18. Divider
   ========================================================================== */

.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.divider-text {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.divider-text::before,
.divider-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ==========================================================================
   19. Activity Timeline
   ========================================================================== */

.timeline-item {
  display: flex;
  gap: 14px;
  position: relative;
}

.timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
  margin-top: 5px;
  position: relative;
}

.timeline-item:not(:last-child) .timeline-dot::after {
  content: '';
  position: absolute;
  top: 15px;
  left: 4px;
  width: 2px;
  height: calc(100% + 14px);
  background: var(--border);
}

[dir="rtl"] .timeline-item:not(:last-child) .timeline-dot::after {
  left: auto;
  right: 4px;
}

.timeline-content {
  padding-bottom: 20px;
}

.timeline-text {
  font-size: 13px;
  color: var(--text-primary);
}

.timeline-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ==========================================================================
   RTL Overrides for Components
   ========================================================================== */

/* Tooltip RTL */
[dir="rtl"] .tooltip-text {
  left: auto;
  right: 50%;
  transform: translateX(50%);
}

[dir="rtl"] .tooltip-text::after {
  left: auto;
  right: 50%;
  transform: translateX(50%);
}

/* Modal footer in RTL — buttons align start */
[dir="rtl"] .modal-footer {
  justify-content: flex-start;
}

/* Modal header close button position */
[dir="rtl"] .modal-close {
  margin-inline-start: 0;
}

/* Toast close button */
[dir="rtl"] .toast-close {
  margin-inline-end: 0;
}

/* Alert close button */
[dir="rtl"] .alert-close {
  margin-inline-end: 0;
}

/* Table sort icons */
[dir="rtl"] .sort-icon {
  transform: scaleX(-1);
}

/* Pagination arrows */
[dir="rtl"] .pagination .page-item .fa-chevron-left {
  transform: scaleX(-1);
}

[dir="rtl"] .pagination .page-item .fa-chevron-right {
  transform: scaleX(-1);
}
