/* ============================================================
   FlowForg ERP — UX Enhancements for Data Entry
   Version: 1.0
   Purpose: Improve the data entry experience across all modules
   ============================================================ */

/* ============================================================
   1. FORM FIELD IMPROVEMENTS
   ============================================================ */

/* --- Better focus states --- */
.input-field input[type="text"]:focus,
.input-field input[type="email"]:focus,
.input-field input[type="password"]:focus,
.input-field input[type="number"]:focus,
.input-field input[type="tel"]:focus,
.input-field input[type="url"]:focus,
.input-field input[type="date"]:focus,
.input-field textarea.materialize-textarea:focus {
  border-bottom: 2px solid #1565C0 !important;
  box-shadow: 0 1px 0 0 #1565C0 !important;
}
.input-field input[type="text"]:focus + label,
.input-field input[type="email"]:focus + label,
.input-field input[type="password"]:focus + label,
.input-field input[type="number"]:focus + label,
.input-field input[type="tel"]:focus + label,
.input-field input[type="url"]:focus + label,
.input-field textarea.materialize-textarea:focus + label {
  color: #1565C0 !important;
}

/* --- Active input field highlight (subtle background) --- */
.input-field input:focus:not([readonly]),
.input-field textarea:focus:not([readonly]) {
  background-color: #F5F9FF;
  transition: background-color 0.2s ease;
}
.input-field input:not(:focus),
.input-field textarea:not(:focus) {
  background-color: transparent;
  transition: background-color 0.2s ease;
}

/* --- Required field indicator --- */
.input-field input[required] + label::after,
.input-field textarea[required] + label::after,
.input-field select[required] + label::after {
  content: ' *';
  color: #e53935;
  font-weight: 600;
}

/* --- Readonly field dimming --- */
.input-field input[readonly],
.input-field textarea[readonly] {
  color: #757575;
  border-bottom: 1px dotted #bdbdbd !important;
  cursor: not-allowed;
}

/* --- Invalid/error state --- */
.input-field input.invalid:not(:focus),
.input-field input:invalid:not(:focus):not(:placeholder-shown),
.input-field textarea.invalid:not(:focus) {
  border-bottom: 2px solid #e53935 !important;
  box-shadow: 0 1px 0 0 #e53935 !important;
}
.input-field .field-error-message {
  display: block;
  font-size: 0.75rem;
  color: #e53935;
  margin-top: 2px;
  min-height: 0;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.2s, transform 0.2s;
}
.input-field .field-error-message.visible {
  opacity: 1;
  transform: translateY(0);
}

/* --- Success state for validated fields --- */
.input-field input.valid:not(:placeholder-shown):not([readonly]),
.input-field input:valid:not(:focus):not(:placeholder-shown):not([readonly]):not(.datepicker):not(.autocompletezero):not(.select-dropdown) {
  border-bottom: 1px solid #43A047 !important;
}

/* --- Better select dropdown styling --- */
.select-wrapper input.select-dropdown {
  border-bottom: 1px solid #9e9e9e;
}
.select-wrapper input.select-dropdown:focus {
  border-bottom: 2px solid #1565C0 !important;
}

/* --- Improved input field spacing --- */
.input-field {
  margin-top: 0.8rem;
  margin-bottom: 0.8rem;
}
.row .input-field .prefix ~ label {
  margin-left: 2.5rem;
}


/* ============================================================
   2. TAB NAVIGATION IMPROVEMENTS
   ============================================================ */

/* --- Better tab styling with active indicator --- */
.tabs {
  border-bottom: 1px solid #e0e0e0;
  background-color: transparent !important;
  height: 48px;
}
.tabs .tab a {
  font-weight: 500;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: color 0.25s, border-bottom 0.25s;
  padding: 0 20px;
  height: 48px;
  line-height: 48px;
  color: #616161 !important;
}
.tabs .tab a:hover {
  color: #1565C0 !important;
  background-color: rgba(21, 101, 192, 0.04);
}
.tabs .tab a.active {
  color: #1565C0 !important;
  border-bottom: 3px solid #1565C0;
  font-weight: 600;
}
.tabs .indicator {
  background-color: #1565C0 !important;
  height: 3px;
}

/* --- Tab keyboard shortcut hints --- */
.tab a .tab-shortcut {
  display: inline-block;
  font-size: 0.65rem;
  color: #9e9e9e;
  background: #f5f5f5;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 6px;
  font-weight: 400;
  vertical-align: middle;
  border: 1px solid #e0e0e0;
  line-height: 1.3;
}


/* ============================================================
   3. CARD & CONTAINER IMPROVEMENTS
   ============================================================ */

/* --- Card subtle shadow and border --- */
main .card {
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 
              0 1px 2px rgba(0,0,0,0.12);
  transition: box-shadow 0.2s ease;
}
main .card:hover {
  box-shadow: 0 2px 6px rgba(0,0,0,0.1), 
              0 2px 4px rgba(0,0,0,0.08);
}

/* --- Better card content padding --- */
main .card .card-content {
  padding: 20px 24px;
}

/* --- Section dividers within forms --- */
.form-section-divider {
  border: none;
  border-top: 1px solid #e0e0e0;
  margin: 1.5rem 0;
}
.form-section-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #424242;
  margin: 1.5rem 0 0.5rem 0;
  padding-bottom: 0.3rem;
  border-bottom: 2px solid #1565C0;
  display: inline-block;
}


/* ============================================================
   4. TABLE / LIST IMPROVEMENTS
   ============================================================ */

/* --- Better table styling --- */
table.full-bordered-new,
table.striped,
table.highlight {
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  overflow: hidden;
}
table.full-bordered-new thead th,
table.striped thead th,
table.highlight thead th {
  background: #f8f9fa;
  font-weight: 600;
  font-size: 0.85rem;
  color: #424242;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 12px 15px;
  border-bottom: 2px solid #dee2e6;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
table tbody td {
  padding: 10px 15px;
  font-size: 0.88rem;
  vertical-align: middle;
  border-bottom: 1px solid #f0f0f0;
}
table.highlight tbody tr:hover {
  background-color: #EDF4FE !important;
}

/* --- Row hover actions (show edit/delete on hover) --- */
table tbody tr .row-actions {
  opacity: 0.3;
  transition: opacity 0.15s ease;
}
table tbody tr:hover .row-actions {
  opacity: 1;
}

/* --- Empty table state --- */
.table-empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: #9e9e9e;
}
.table-empty-state i.zmdi {
  font-size: 3rem;
  display: block;
  margin-bottom: 1rem;
  color: #bdbdbd;
}
.table-empty-state .empty-title {
  font-size: 1.1rem;
  font-weight: 500;
  color: #757575;
  margin-bottom: 0.3rem;
}
.table-empty-state .empty-subtitle {
  font-size: 0.9rem;
  color: #9e9e9e;
}
.table-empty-state .btn {
  margin-top: 1rem;
}

/* --- Better pagination --- */
.pagination-container {
  margin-top: 1rem;
  padding: 0.5rem 0;
}
.pagination li a,
.pagination li span {
  font-size: 0.85rem;
  padding: 0 10px;
  height: 32px;
  line-height: 32px;
}
.pagination li.active a {
  background-color: #1565C0 !important;
}

/* --- Per-page selector styling --- */
select[name="per_page"] {
  max-width: 80px;
  font-size: 0.85rem;
  padding: 0 8px;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  background-color: #fff;
}

/* --- Loading animation for pagination --- */
.per_page_loading_anim {
  text-align: center;
  padding: 2rem 0;
}


/* ============================================================
   5. BUTTON IMPROVEMENTS
   ============================================================ */

/* --- Consistent button sizing and spacing --- */
.btn, .btn-flat, .btn-large {
  border-radius: 4px;
  text-transform: none;
  font-weight: 500;
  letter-spacing: 0.3px;
  transition: all 0.2s ease;
}
.btn {
  height: 36px;
  line-height: 36px;
  padding: 0 20px;
  font-size: 0.9rem;
}
.btn:hover {
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* --- Save/Submit button emphasis --- */
.btn[type="submit"],
button.btn-save,
.btn.save-action {
  min-width: 120px;
  font-weight: 600;
}

/* --- Button groups (for form action bars) --- */
.form-action-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 1rem 0;
  margin-top: 1rem;
  border-top: 1px solid #f0f0f0;
}
.form-action-bar .btn + .btn,
.form-action-bar .btn + .btn-flat {
  margin-left: 0; /* gap handles spacing */
}
.form-action-bar .spacer {
  flex: 1;
}

/* --- Disabled button state --- */
.btn[disabled],
.btn.disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none !important;
}

/* --- Button with loading spinner --- */
.btn.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn.btn-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btn-spinner 0.6s linear infinite;
}
@keyframes btn-spinner {
  to { transform: rotate(360deg); }
}

/* --- Icon-only buttons (used in table rows) --- */
.btn-icon {
  width: 32px;
  height: 32px;
  line-height: 32px;
  padding: 0;
  text-align: center;
  border-radius: 50%;
  background: transparent;
  color: #616161;
  box-shadow: none;
}
.btn-icon:hover {
  background: rgba(0,0,0,0.06);
  box-shadow: none;
}
.btn-icon i {
  font-size: 1.1rem;
  line-height: 32px;
}


/* ============================================================
   6. MODAL IMPROVEMENTS
   ============================================================ */

.modal {
  border-radius: 8px;
  max-height: 85vh;
}
.modal .modal-content {
  padding: 24px 24px 8px;
}
.modal .modal-content h4 {
  font-size: 1.3rem;
  font-weight: 600;
  color: #212121;
  margin-bottom: 1rem;
}
.modal .modal-footer {
  padding: 8px 24px;
  border-top: 1px solid #f0f0f0;
}

/* --- Modal overlay --- */
.modal-overlay {
  background: rgba(0, 0, 0, 0.4) !important;
}

/* --- Delete confirmation modal --- */
.modal-delete-table-row .modal-content p {
  font-size: 1rem;
  color: #424242;
}
.modal-delete-table-row .btn.red {
  border-radius: 4px;
}


/* ============================================================
   7. DROPDOWN MENU IMPROVEMENTS (Row Actions)
   ============================================================ */

.dropdown-content {
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  border: 1px solid #e0e0e0;
  min-width: 160px;
}
.dropdown-content li > a {
  font-size: 0.88rem;
  color: #424242;
  padding: 10px 16px;
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dropdown-content li > a > i {
  font-size: 1.1rem;
  width: 24px;
  text-align: center;
  color: #757575;
}
.dropdown-content li > a:hover {
  background-color: #f5f5f5;
  color: #1565C0;
}
.dropdown-content li > a:hover > i {
  color: #1565C0;
}


/* ============================================================
   8. SEARCH / FILTER IMPROVEMENTS
   ============================================================ */

/* --- Search tab card --- */
#search .card,
#search form {
  max-width: 600px;
  margin: 0 auto;
}

/* --- Inline search bar (above tables) --- */
.table-search-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.table-search-bar .input-field {
  margin: 0;
  flex: 1;
  min-width: 200px;
}
.table-search-bar .input-field input {
  margin: 0;
  height: 2.5rem;
}
.table-search-bar .input-field label {
  top: -0.5rem;
}
.table-search-bar .btn {
  margin: 0;
  flex-shrink: 0;
}

/* --- Filter pills / badge count --- */
.filter-badge {
  display: inline-flex;
  align-items: center;
  background: #E3F2FD;
  color: #1565C0;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 16px;
  margin: 2px 4px;
}
.filter-badge .remove-filter {
  margin-left: 6px;
  cursor: pointer;
  font-size: 0.7rem;
  color: #1565C0;
  opacity: 0.7;
}
.filter-badge .remove-filter:hover {
  opacity: 1;
}


/* ============================================================
   9. TOAST / NOTIFICATION IMPROVEMENTS
   ============================================================ */

/* --- Toastr positioning fix --- */
#toast-container {
  bottom: 16px !important;
  right: 16px !important;
  left: auto !important;
}
#toast-container > div {
  border-radius: 6px !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
  padding: 12px 16px !important;
  font-size: 0.9rem !important;
  min-width: 250px !important;
  max-width: 400px !important;
  opacity: 1 !important;
}

/* --- Save success flash --- */
.save-flash {
  animation: flashGreen 0.5s ease;
}
@keyframes flashGreen {
  0%   { background-color: inherit; }
  30%  { background-color: #E8F5E9; }
  100% { background-color: inherit; }
}


/* ============================================================
   10. KEYBOARD SHORTCUT HELPER (BOTTOM BAR)
   ============================================================ */

.keyboard-shortcuts-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #263238;
  color: #B0BEC5;
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 0.78rem;
  z-index: 999;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.15);
  flex-wrap: wrap;
}
.keyboard-shortcuts-bar .shortcut-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.keyboard-shortcuts-bar kbd {
  display: inline-block;
  background: #37474F;
  color: #ECEFF1;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.72rem;
  font-family: 'Inconsolata', monospace;
  border: 1px solid #455A64;
  min-width: 20px;
  text-align: center;
}
.keyboard-shortcuts-bar .shortcut-label {
  color: #90A4AE;
}

/* Push content up to account for shortcuts bar */
body.has-shortcuts-bar main {
  padding-bottom: 40px;
}


/* ============================================================
   11. RESPONSIVE / MOBILE IMPROVEMENTS
   ============================================================ */

@media only screen and (max-width: 600px) {
  /* Stack form fields fully */
  .input-field {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
  }
  
  /* Full-width buttons on mobile */
  .form-action-bar {
    flex-direction: column;
  }
  .form-action-bar .btn {
    width: 100%;
  }
  
  /* Table horizontal scroll indicator */
  .table-responsive {
    position: relative;
  }
  .table-responsive::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 30px;
    height: 100%;
    background: linear-gradient(to left, rgba(255,255,255,0.9), transparent);
    pointer-events: none;
    z-index: 1;
  }
  
  /* Compact table cells on mobile */
  table tbody td {
    padding: 8px 10px;
    font-size: 0.82rem;
  }
  table thead th {
    padding: 8px 10px;
    font-size: 0.78rem;
  }
  
  /* Card padding reduction */
  main .card .card-content {
    padding: 12px 12px;
  }
  
  /* Keyboard shortcuts bar: hide on mobile (no keyboard) */
  .keyboard-shortcuts-bar {
    display: none;
  }
  
  /* Better dropdown on mobile */
  .dropdown-content {
    min-width: 140px;
  }
  
  /* Tabs scrollable on mobile */
  .tabs {
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .tabs .tab {
    float: none;
    display: inline-block;
    min-width: 80px;
  }
}

@media only screen and (max-width: 992px) and (min-width: 601px) {
  main .card .card-content {
    padding: 16px 20px;
  }
}


/* ============================================================
   12. FORM PROGRESS / STEP INDICATOR
   ============================================================ */

.form-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 0 1.5rem;
  gap: 0;
}
.form-step {
  display: flex;
  align-items: center;
  gap: 0;
}
.form-step-number {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e0e0e0;
  color: #757575;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.3s;
}
.form-step.active .form-step-number {
  background: #1565C0;
  color: #fff;
}
.form-step.completed .form-step-number {
  background: #43A047;
  color: #fff;
}
.form-step-label {
  font-size: 0.8rem;
  color: #9e9e9e;
  margin-left: 6px;
  font-weight: 500;
}
.form-step.active .form-step-label {
  color: #1565C0;
}
.form-step.completed .form-step-label {
  color: #43A047;
}
.form-step-connector {
  width: 40px;
  height: 2px;
  background: #e0e0e0;
  margin: 0 4px;
}
.form-step.completed + .form-step-connector,
.form-step.completed ~ .form-step-connector {
  background: #43A047;
}


/* ============================================================
   13. LOADING SKELETON (for AJAX-loaded tables)
   ============================================================ */

.skeleton-row {
  display: flex;
  gap: 16px;
  padding: 12px 15px;
  border-bottom: 1px solid #f0f0f0;
}
.skeleton-cell {
  height: 14px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: 4px;
}
.skeleton-cell.w-sm { width: 60px; }
.skeleton-cell.w-md { width: 120px; }
.skeleton-cell.w-lg { width: 200px; }
.skeleton-cell.w-xl { width: 100%; flex: 1; }

@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}


/* ============================================================
   14. ACCESSIBILITY IMPROVEMENTS
   ============================================================ */

/* --- Focus ring for keyboard navigation --- */
*:focus-visible {
  outline: 2px solid #1565C0;
  outline-offset: 2px;
}
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none; /* Materialize handles these */
}

/* --- Skip to content link --- */
.skip-to-content {
  position: absolute;
  top: -100px;
  left: 0;
  background: #1565C0;
  color: #fff;
  padding: 8px 16px;
  z-index: 10000;
  font-size: 0.9rem;
  transition: top 0.2s;
}
.skip-to-content:focus {
  top: 0;
}

/* --- Better contrast for helper text --- */
.input-field .helper-text {
  font-size: 0.75rem;
  color: #757575;
  min-height: 18px;
}


/* ============================================================
   15. STATUS BADGES (for tables)
   ============================================================ */

.status-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.status-badge.status-active,
.status-badge.status-completed,
.status-badge.status-paid {
  background: #E8F5E9;
  color: #2E7D32;
}
.status-badge.status-pending,
.status-badge.status-draft {
  background: #FFF8E1;
  color: #F57F17;
}
.status-badge.status-inactive,
.status-badge.status-cancelled {
  background: #FFEBEE;
  color: #C62828;
}
.status-badge.status-processing,
.status-badge.status-in-progress {
  background: #E3F2FD;
  color: #1565C0;
}


/* ============================================================
   16. QUICK-ADD PATTERN (inline row add)
   ============================================================ */

.quick-add-row {
  border: 2px dashed #e0e0e0;
  border-radius: 4px;
  padding: 8px;
  margin-top: 8px;
  background: #FAFAFA;
  transition: border-color 0.2s;
}
.quick-add-row:hover,
.quick-add-row:focus-within {
  border-color: #1565C0;
  background: #F5F9FF;
}
.quick-add-row input {
  border: none !important;
  box-shadow: none !important;
  margin: 0 !important;
  height: 2rem !important;
}


/* ============================================================
   17. DATA ENTRY HELPERS
   ============================================================ */

/* --- Numeric input right-aligned --- */
input.right-align,
input[data-type="currency"],
input[data-type="quantity"],
td.amount input,
td.qty input {
  text-align: right;
  font-family: 'Inconsolata', monospace;
}

/* --- Large text input for scanner/barcode --- */
.large-text-input {
  font-size: 1.4rem !important;
  letter-spacing: 2px;
  font-family: 'Inconsolata', monospace;
}

/* --- Autosave indicator --- */
.autosave-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: #9e9e9e;
  transition: color 0.3s;
}
.autosave-indicator.saving {
  color: #FF9800;
}
.autosave-indicator.saved {
  color: #43A047;
}
.autosave-indicator i {
  font-size: 0.9rem;
}


/* ============================================================
   18. SCROLLBAR STYLING (subtle, modern)
   ============================================================ */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #c0c0c0;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #999;
}

/* --- Scrollbar for table-responsive only --- */
.table-responsive::-webkit-scrollbar {
  height: 8px;
}


/* ============================================================
   19. TRANSITION / ANIMATION HELPERS
   ============================================================ */

.fade-in {
  animation: fadeIn 0.3s ease-in;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.slide-down {
  animation: slideDown 0.3s ease-out;
}
@keyframes slideDown {
  from { opacity: 0; max-height: 0; }
  to   { opacity: 1; max-height: 500px; }
}

/* --- Smooth tab transitions --- */
.tabs-content {
  transition: opacity 0.15s ease;
}


/* ============================================================
   20. BREADCRUMB / PAGE HEADER
   ============================================================ */

.page-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  margin-bottom: 4px;
}
.page-header-bar .page-title-text {
  font-size: 1.2rem;
  font-weight: 600;
  color: #212121;
}
.page-header-bar .page-subtitle {
  font-size: 0.85rem;
  color: #9e9e9e;
  margin-left: 8px;
}
.page-header-bar .page-actions {
  display: flex;
  gap: 8px;
}


/* ============================================================
   21. PRINT HELPERS (hidden on screen)
   ============================================================ */

@media print {
  .keyboard-shortcuts-bar,
  .form-action-bar,
  .table-search-bar,
  nav,
  .side-nav,
  .btn,
  .status-bar,
  .tabs {
    display: none !important;
  }
  main .card {
    box-shadow: none !important;
    border: none !important;
  }
}
