/* Premium CSS Styling for ElCorp PWA */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: rgba(30, 41, 59, 0.45);
  --bg-input: rgba(15, 23, 42, 0.6);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #6366f1;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent-blue: #38bdf8;
  --accent-indigo: #6366f1;
  --accent-purple: #a855f7;
  --accent-success: #10b981;
  --accent-danger: #ef4444;
  --font-family: 'Outfit', sans-serif;
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --glass-blur: blur(16px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(56, 189, 248, 0.1) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* App Header */
header {
  background: rgba(10, 14, 23, 0.7);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header .logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-indigo));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

header .logo img {
  width: 32px;
  height: 32px;
}

header .user-profile {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.btn {
  font-family: var(--font-family);
  font-weight: 500;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: var(--transition-smooth);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-purple));
  color: #fff;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.3);
}

/* Main Container */
main {
  flex: 1;
  padding: 2rem;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* Login Container */
.login-container {
  max-width: 420px;
  width: 90%;
  margin: 10vh auto;
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
  animation: fadeIn 0.5s ease-out;
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-header h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: #fff;
}

.login-header p {
  color: var(--text-secondary);
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.form-control {
  width: 100%;
  padding: 0.75rem 1rem;
  font-family: var(--font-family);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: #fff;
  transition: var(--transition-smooth);
}

.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

/* Dashboard View */
.dashboard-view {
  animation: fadeIn 0.4s ease-out;
}

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

.dashboard-header h1 {
  font-size: 2.25rem;
  font-weight: 700;
  color: #fff;
}

/* Filter Card */
.filter-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 200; /* Stacks dropdown menus above receipt cards below */
}

/* Receipt Grid */
.receipts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.receipt-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  transition: var(--transition-smooth);
  display: flex;
  flex-direction: column;
}

.receipt-card:hover {
  transform: translateY(-5px);
  border-color: rgba(99, 102, 241, 0.3);
}

.receipt-image-container {
  height: 200px;
  background: #0f172a;
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

.receipt-image-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: var(--transition-smooth);
}

.receipt-card:hover .receipt-image-container img {
  transform: scale(1.05);
}

.receipt-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-blue);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.receipt-body {
  padding: 1.25rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.receipt-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #fff;
}

.receipt-meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.receipt-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  flex-grow: 1;
}

.receipt-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.receipt-actions button {
  flex: 1;
}

/* Modal Styling */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(7, 10, 18, 0.85);
  backdrop-filter: var(--glass-blur);
  z-index: 1000;
  display: none;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
  animation: fadeIn 0.3s ease-out;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
  animation: slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.modal-header h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: #fff;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.close-btn:hover {
  color: #fff;
}

.modal-body {
  padding: 1.5rem;
}

/* Capture Area */
.capture-box {
  border: 2px dashed rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: var(--transition-smooth);
  margin-bottom: 1.5rem;
  position: relative;
  background: rgba(255, 255, 255, 0.02);
}

.capture-box:hover {
  border-color: var(--accent-indigo);
  background: rgba(99, 102, 241, 0.04);
}

.capture-icon {
  font-size: 2.5rem;
  color: var(--accent-blue);
  margin-bottom: 1rem;
}

.capture-preview {
  width: 100%;
  border-radius: 8px;
  display: none;
  max-height: 250px;
  object-fit: contain;
  margin-top: 1rem;
  box-shadow: var(--shadow-lg);
}

/* Print View Overlay */
#print-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  z-index: 2000;
  display: none;
  justify-content: center;
  align-items: center;
}

#print-area {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fff;
  padding: 0;
  margin: 0;
  width: 100vw;
  height: 100vh;
}

/* Notice inside app */
.alert {
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
  display: none;
  border: 1px solid transparent;
}

.alert-danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
}

.alert-success {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.3);
  color: #34d399;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  background: var(--bg-card);
  border: 1px dashed var(--border-color);
  border-radius: 16px;
  grid-column: 1 / -1;
}

.empty-state-icon {
  font-size: 3rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.empty-state h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.empty-state p {
  color: var(--text-secondary);
}

/* Footer styling */
footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border-color);
  margin-top: auto;
}

/* Searchable Custom Dropdown Styles */
.custom-select-container {
  position: relative;
  width: 100%;
}

.custom-select-trigger {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.9rem;
  background: rgba(30, 41, 59, 0.4);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: var(--transition-smooth);
  user-select: none;
}

.custom-select-trigger:hover {
  border-color: var(--accent-indigo);
  background: rgba(30, 41, 59, 0.6);
}

.custom-select-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: rgba(15, 23, 42, 0.98);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  margin-top: 4px;
  max-height: 250px;
  overflow: hidden;
  z-index: 2100;
  display: none;
  box-shadow: var(--shadow-lg);
  flex-direction: column;
}

.custom-select-dropdown.open {
  display: flex;
}

.custom-select-search-box {
  padding: 8px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(15, 23, 42, 0.98);
}

.custom-select-search-input {
  width: 100%;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: #ffffff;
  font-size: 0.85rem;
}

.custom-select-search-input:focus {
  outline: none;
  border-color: var(--accent-indigo);
}

.custom-select-options {
  max-height: 190px;
  overflow-y: auto;
  flex: 1;
}

.custom-select-option {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: var(--transition-smooth);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.custom-select-option:hover, .custom-select-option.selected {
  background: rgba(99, 102, 241, 0.15);
  color: #ffffff;
}

.custom-select-option .option-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.custom-select-arrow {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid var(--text-muted);
  transition: transform 0.2s ease;
}

.custom-select-container.open .custom-select-arrow {
  transform: rotate(180deg);
}

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

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

/* Bottom Navigation Tab Bar Styling */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  display: none; /* Controlled dynamically by JS */
  justify-content: space-around;
  align-items: center;
  padding: 0.5rem 0;
  z-index: 1000;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
}

.bottom-nav .nav-tab {
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  padding: 0.4rem 1rem;
  border-radius: 8px;
  transition: var(--transition-smooth);
  font-size: 0.75rem;
  font-weight: 500;
}

.bottom-nav .nav-tab svg {
  stroke: var(--text-muted);
  transition: var(--transition-smooth);
}

.bottom-nav .nav-tab:hover {
  background: rgba(255, 255, 255, 0.02);
}

.bottom-nav .nav-tab.active {
  color: var(--accent-indigo);
}

.bottom-nav .nav-tab.active svg {
  stroke: var(--accent-indigo);
}

body.logged-in {
  padding-bottom: 70px !important;
}

/* Responsive Overrides */
@media (max-width: 768px) {
  header {
    padding: 1rem;
  }
  main {
    padding: 1rem;
  }
  .dashboard-header h1 {
    font-size: 1.75rem;
  }
  .filter-card {
    grid-template-columns: 1fr;
  }
  .modal-content {
    max-height: 95vh;
  }
}

@media (max-width: 576px) {
  header {
    padding: 0.75rem 1rem !important;
    flex-direction: column !important;
    gap: 0.75rem !important;
    align-items: center !important;
    text-align: center !important;
  }
  
  header .logo {
    font-size: 1.25rem !important;
  }
  
  header .user-profile {
    width: 100% !important;
    justify-content: center !important;
    gap: 0.5rem !important;
  }
  
  header .user-profile button span {
    display: none !important; /* Icon-only on small mobile screens */
  }
  
  header .user-profile button {
    padding: 0.4rem 0.6rem !important;
  }
  
  main {
    padding: 0.75rem !important;
  }
  
  .dashboard-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.75rem !important;
    text-align: center !important;
  }
  
  .dashboard-header h1 {
    font-size: 1.5rem !important;
  }
  
  .dashboard-header p {
    font-size: 0.85rem !important;
  }
  
  #open-upload-modal-btn {
    width: 100% !important;
    padding: 0.75rem !important;
  }
  
  .filter-card {
    padding: 1rem !important;
    margin-bottom: 1.25rem !important;
    gap: 0.75rem !important;
  }
  
  .receipts-grid {
    grid-template-columns: 1fr !important; /* Single column on mobile */
    gap: 1rem !important;
  }
  
  .receipt-card {
    border-radius: 12px !important;
  }
  
  .receipt-image-container {
    height: 180px !important;
  }
  
  /* Selection bar optimization */
  #selection-control-bar .card-body {
    padding: 0.5rem 0.75rem !important;
    justify-content: center !important;
    gap: 0.5rem !important;
  }
  
  /* Modal optimization for mobile */
  .modal {
    padding: 0.5rem !important;
  }
  
  .modal-content {
    border-radius: 12px !important;
    max-height: 96vh !important;
  }
  
  .modal-header {
    padding: 0.75rem 1rem !important;
  }
  
  .modal-header h3 {
    font-size: 1.1rem !important;
  }
  
  .modal-body {
    padding: 0.75rem 1rem !important;
  }
  
  .capture-box {
    padding: 1rem !important;
    margin-bottom: 0.75rem !important;
  }
  
  .capture-icon {
    font-size: 2rem !important;
    margin-bottom: 0.5rem !important;
  }
  
  .form-group {
    margin-bottom: 0.75rem !important;
  }
  
  .form-group label {
    font-size: 0.85rem !important;
    margin-bottom: 0.25rem !important;
  }
  
  .form-control {
    padding: 0.5rem 0.75rem !important;
    font-size: 0.9rem !important;
  }
  
  /* Action buttons inside cards */
  .receipt-actions {
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
  }
  
  .receipt-actions button {
    flex: 1 1 calc(50% - 0.25rem) !important;
    padding: 0.5rem 0.75rem !important;
    font-size: 0.85rem !important;
  }
  
  .receipt-actions button.btn-delete {
    flex: 1 1 100% !important; /* Delete spans full width for safety */
  }
}

/* PRINT OPTIMIZATION CSS */
@media print {
  /* Hide all regular web interface elements, navigation bars, modals, alerts */
  header, nav, main, footer, .modal, .bottom-nav, #bottom-nav, #alert-box, .alert, .custom-select-container, .custom-select-menu, .dashboard-header, .filter-card, #selection-control-bar, .cropper-container {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    max-height: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    overflow: hidden !important;
  }

  body > *:not(#print-overlay) {
    display: none !important;
    visibility: hidden !important;
  }

  html, body {
    background: #ffffff !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* Force display only the printing target and configure layout */
  #print-overlay {
    display: block !important;
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: auto !important;
    background: #ffffff !important;
    color: #000000 !important;
    z-index: 9999999 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  #print-overlay, #print-overlay * {
    visibility: visible !important;
  }

  #print-single-area {
    width: 100% !important;
    height: auto !important;
  }

  #print-area {
    visibility: visible !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    background: #ffffff !important;
    width: 100% !important;
    height: auto !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  #print-area img {
    visibility: visible !important;
    /* Scale logic: Render at natural size, but scale down if exceeds folio page */
    max-width: 100% !important;
    max-height: 320mm !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
    display: block !important;
    margin: auto !important;
    page-break-inside: avoid !important;
  }

  #print-report-area {
    width: 100% !important;
    background: #ffffff !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .print-report-grid {
    display: grid !important;
    grid-template-columns: repeat(6, 1fr) !important; /* 6 Column layout to fit 1-col, 2-col, and 3-col items side by side */
    gap: 3px !important;
    width: 100% !important;
  }

  /* 1 Column item: spans full width (6/6 columns), height follows content */
  .print-receipt-card.card-cols-1 {
    grid-column: span 6 !important;
    height: auto !important;
    max-height: 320mm !important;
  }
  .print-receipt-card.card-cols-1 .print-receipt-image {
    height: auto !important;
    max-height: 310mm !important;
    object-fit: contain !important;
  }

  /* 2 Columns item: spans half width (3/6 columns), height follows content */
  .print-receipt-card.card-cols-2 {
    grid-column: span 3 !important;
    height: auto !important;
    max-height: 158mm !important;
  }
  .print-receipt-card.card-cols-2 .print-receipt-image {
    height: auto !important;
    max-height: 148mm !important;
    width: 100% !important;
    object-fit: contain !important;
  }

  /* 3 Columns item: spans one-third width (2/6 columns), height follows content */
  .print-receipt-card.card-cols-3 {
    grid-column: span 2 !important;
    height: auto !important;
    max-height: 105mm !important;
  }
  .print-receipt-card.card-cols-3 .print-receipt-image {
    height: auto !important;
    max-height: 97mm !important;
    width: 100% !important;
    object-fit: contain !important;
  }

  .print-receipt-card {
    border: 1px solid #000000 !important; /* Clean thin black borders */
    border-radius: 0px !important; /* Square corners for tight alignment */
    padding: 2px !important;
    page-break-inside: avoid !important; /* Avoid split cards across pages */
    display: flex !important;
    flex-direction: column !important;
    background: #ffffff !important;
    box-sizing: border-box !important;
  }

  .print-receipt-title {
    font-size: 9pt !important;
    font-weight: bold !important;
    margin-bottom: 2px !important;
    border-bottom: 1px solid #000000 !important;
    padding-bottom: 1px !important;
    color: #000000 !important;
    text-transform: uppercase !important;
    text-align: center !important; /* Center project name */
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .print-receipt-image {
    width: 100% !important;
    object-fit: contain !important;
  }

  /* Configure Folio / F4 Paper size specifically: 215mm width by 330mm height with small 3mm margins */
  @page {
    size: 215mm 330mm;
    margin: 3mm;
  }
}

/* Cropper Large View Mode */
.cropper-container {
  border-radius: 12px;
  overflow: hidden;
  max-height: 70vh !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
