/* ============================================================
   PROJECT FOLDER — Design System & PWA Styles
   ============================================================ */

/* --- 1. Design Tokens (CSS Custom Properties) --- */
:root {
  /* Primary Palette */
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --primary-light: #dbeafe;
  --bg-primary-light: #eff6ff;

  /* Semantic Colors */
  --success: #16a34a;
  --success-light: #dcfce7;
  --bg-success-light: #f0fdf4;

  --error: #dc2626;
  --error-light: #fee2e2;
  --bg-error-light: #fef2f2;

  --warning: #f59e0b;
  --warning-light: #fef3c7;

  --info: #0ea5e9;

  /* Neutrals */
  --text-main: #0f172a;
  --text-muted: #64748b;
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --border-color: #e2e8f0;

  /* Typography */
  --font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;

  /* Spacing & Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.05);

  /* Z-Index Scale */
  --z-navbar: 1030;
  --z-mobile-nav: 1020;
  --z-toast: 1080;
  --z-offline-banner: 1090;
  --z-modal-backdrop: 1040;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Safe areas for PWA standalone */
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* --- 2. Global Reset & Base --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  background: var(--bg-body);
  color: var(--text-main);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
}

/* --- 3. Utility Classes --- */
.text-main { color: var(--text-main) !important; }
.text-primary { color: var(--primary) !important; }
.text-error { color: var(--error) !important; }
.text-success { color: var(--success) !important; }
.text-info { color: var(--info) !important; }
.text-muted { color: var(--text-muted) !important; }

.bg-primary-light { background: var(--bg-primary-light) !important; }
.bg-success-light { background: var(--bg-success-light) !important; }
.bg-error-light { background: var(--bg-error-light) !important; }

.fw-500 { font-weight: 500 !important; }
.fw-600 { font-weight: 600 !important; }

.border-dashed {
  border: 2px dashed var(--border-color) !important;
}

.x-small { font-size: 0.7rem !important; }

/* --- 4. Page Transition Animation --- */
.fade-in {
  animation: fadeInUp var(--transition-slow) ease-out both;
}

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

/* --- 5. Navbar --- */
.navbar {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  z-index: var(--z-navbar);
  transition: box-shadow var(--transition-normal);
  border-bottom: 1px solid var(--border-color) !important;
}

.navbar .nav-link {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-muted);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.navbar .nav-link:hover,
.navbar .nav-link.active {
  color: var(--primary);
  background: var(--bg-primary-light);
}

/* --- 6. Mobile Bottom Navigation --- */
.mobile-nav-fixed {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 0.35rem 0;
  padding-bottom: calc(0.35rem + var(--safe-area-bottom));
  z-index: var(--z-mobile-nav);
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0.35rem 0.75rem;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  min-width: 60px;
  -webkit-tap-highlight-color: transparent;
}

.mobile-nav-item i {
  font-size: 1.25rem;
  transition: transform var(--transition-fast);
}

.mobile-nav-item.active {
  color: var(--primary);
}

.mobile-nav-item.active i {
  transform: scale(1.15);
}

.mobile-nav-item:active {
  transform: scale(0.92);
}

/* Add bottom padding to body on mobile for bottom nav */
@media (max-width: 991.98px) {
  body {
    padding-bottom: calc(70px + var(--safe-area-bottom));
  }
}

/* --- 7. Cards --- */
.card {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  transition: box-shadow var(--transition-normal), transform var(--transition-normal);
}

.stat-card {
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

@media (min-width: 992px) {
  .stat-value {
    font-size: 1.35rem;
  }
}

/* Action Cards */
.action-card {
  border-radius: var(--radius-lg) !important;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.action-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.action-card:active {
  transform: scale(0.98);
}

.action-icon-wrapper {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* --- 8. Buttons Enhancements --- */
.btn {
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: all var(--transition-fast);
}

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

.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

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

.btn-error {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
}

.btn-outline-error {
  border-color: var(--error);
  color: var(--error);
}

.btn-outline-error:hover {
  background: var(--error);
  color: #fff;
}

.btn-xs {
  font-size: 0.75rem;
  padding: 0.25rem 0.75rem;
}

/* Touch-friendly tap targets */
.btn, .form-control, .form-select, .nav-link {
  min-height: 44px;
}

/* --- 9. Forms --- */
.form-control, .form-select {
  border-radius: var(--radius-sm);
  border-color: var(--border-color);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* --- 10. Tables --- */
.table {
  font-size: 0.875rem;
}

.table thead th {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border-color);
  padding: 0.75rem;
}

.table tbody tr {
  transition: background var(--transition-fast);
}

.table tbody tr:hover {
  background: var(--bg-primary-light);
}

.table tbody td {
  padding: 0.75rem;
  vertical-align: middle;
  border-bottom: 1px solid #f1f5f9;
}

/* --- 11. Documentation Styles (preserved from original) --- */
.doc-section { scroll-margin-top: 100px; }
.sidebar-sticky { position: sticky; top: 100px; }
.nav-link.active { background: var(--bg-primary-light); color: var(--primary) !important; font-weight: 600; }
.doc-card { border: none; border-left: 4px solid var(--primary); background: #f8fafc; }
.code-inline { background: #e2e8f0; padding: 0.1rem 0.3rem; border-radius: 4px; font-family: var(--font-mono); font-size: 0.9em; }

/* --- 12. Lock Screen Layout (Ingestor, Income) --- */
.lock-screen {
  overflow: hidden;
}

@media (max-width: 991.98px) {
  .lock-screen {
    height: 100vh;
    height: 100dvh;
  }

  .lock-screen .main-lock-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 56px - 70px);
    min-height: calc(100dvh - 56px - 70px);
    padding-top: 0 !important;
    padding-bottom: 0 !important;
  }
}

/* --- 13. Upload Zone --- */
.upload-zone {
  background: var(--bg-primary-light);
  border: 2px dashed rgba(37, 99, 235, 0.2);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.08);
}

.upload-zone.has-file {
  border-color: var(--success);
  background: var(--bg-success-light);
  border-style: solid;
}

/* --- 14. Camera Preview (PWA) --- */
.camera-preview-container {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: #000;
  aspect-ratio: 4/3;
  max-height: 240px;
}

.camera-preview-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-preview-container canvas {
  display: none;
}

.camera-capture-btn {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid rgba(255,255,255,0.6);
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
  cursor: pointer;
  transition: transform var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-capture-btn:active {
  transform: translateX(-50%) scale(0.9);
}

.camera-capture-btn::after {
  content: '';
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary);
  transition: background var(--transition-fast);
}

.camera-preview-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-lg);
}

/* --- 15. PWA Offline Banner --- */
.pwa-offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  text-align: center;
  padding: 6px 16px;
  padding-top: calc(6px + var(--safe-area-top));
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  z-index: var(--z-offline-banner);
  transform: translateY(-100%);
  transition: transform var(--transition-normal);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.pwa-offline-banner.visible {
  transform: translateY(0);
}

.pwa-offline-banner i {
  margin-right: 6px;
}

/* Push content down when banner is showing */
body.is-offline .navbar {
  margin-top: 32px;
}

body.is-offline .mobile-nav-fixed {
  /* keep bottom nav in place */
}

/* --- 16. Toast Notification System --- */
.pwa-toast-container {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
  max-width: 360px;
  width: calc(100% - 32px);
}

@media (min-width: 992px) {
  .pwa-toast-container {
    bottom: 32px;
    left: auto;
    right: 24px;
    transform: none;
    max-width: 380px;
  }
}

.pwa-toast {
  background: var(--text-main);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-xl);
  pointer-events: auto;
  cursor: pointer;
  animation: toastSlideIn var(--transition-normal) ease-out both;
  will-change: transform, opacity;
  user-select: none;
}

.pwa-toast.toast-success {
  background: linear-gradient(135deg, #16a34a, #15803d);
}

.pwa-toast.toast-error {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
}

.pwa-toast.toast-warning {
  background: linear-gradient(135deg, #f59e0b, #d97706);
}

.pwa-toast.toast-info {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
}

.pwa-toast.toast-out {
  animation: toastSlideOut var(--transition-fast) ease-in both;
}

.pwa-toast i {
  font-size: 1.1rem;
  flex-shrink: 0;
}

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

@keyframes toastSlideOut {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-8px) scale(0.95);
  }
}

/* --- 17. Pending Sync Badge --- */
.pending-sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--warning-light);
  color: #92400e;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  animation: pendingPulse 2s ease-in-out infinite;
}

.pending-sync-row {
  background: #fffbeb !important;
  border-left: 3px solid var(--warning);
}

@keyframes pendingPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* --- 18. Syncing Indicator --- */
.sync-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  background: var(--bg-primary-light);
}

.sync-indicator .spinner-border {
  width: 14px;
  height: 14px;
  border-width: 2px;
}

/* --- 19. Alert overrides --- */
.alert-error-light {
  background: var(--bg-error-light);
  color: var(--error);
}

/* --- 20. Scrollbar Styling --- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* --- 21. Dropdown Enhanced --- */
.dropdown-menu {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
}

/* --- 22. PWA Standalone Mode Adjustments --- */
@media all and (display-mode: standalone) {
  .navbar {
    padding-top: var(--safe-area-top);
  }
}

/* --- 23. Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- 24. Print --- */
@media print {
  .navbar, .mobile-nav-fixed, .pwa-offline-banner, .pwa-toast-container {
    display: none !important;
  }
  body {
    padding: 0;
  }
}
