/* ================================================
   CRUD COMPONENT DESIGN SYSTEM v2.0
   HJ ERP — Modern, Responsive, Informative
   Loaded after application.css (c > a alphabetically)
   so these rules naturally override old crud-* styles.
   ================================================ */

/* ----------------------------------------
   CRUD Design Tokens
   ---------------------------------------- */
:root {
  --crud-surface:       #ffffff;
  --crud-surface-2:     #f8fafc;
  --crud-surface-3:     #f1f5f9;
  --crud-border:        #e2e8f0;
  --crud-border-light:  #f1f5f9;
  --crud-text:          #1e293b;
  --crud-text-muted:    #64748b;
  --crud-text-subtle:   #94a3b8;
  --crud-shadow-sm:     0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --crud-shadow-md:     0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
  --crud-shadow-lg:     0 8px 32px rgba(0,0,0,0.10), 0 4px 12px rgba(0,0,0,0.06);
  --crud-radius:        0.75rem;
  --crud-radius-sm:     0.5rem;
  --crud-radius-xs:     0.375rem;
  --crud-transition:    0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ----------------------------------------
   CRUD Page Header
   ---------------------------------------- */
.crud-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--crud-border);
  gap: 0.75rem;
  flex-wrap: wrap;
}

.crud-header h1 {
  font-weight: 700;
  color: var(--crud-text);
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: -0.3px;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.crud-header h1 i {
  color: var(--hj-primary);
  font-size: 1.2rem;
}

.crud-header .btn-primary {
  padding: 0.5rem 1.125rem;
  font-weight: 600;
  border-radius: var(--crud-radius-sm);
  font-size: 0.875rem;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  box-shadow: 0 2px 8px rgba(218, 165, 32, 0.30);
  transition: all var(--crud-transition);
  white-space: nowrap;
}

.crud-header .btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(218, 165, 32, 0.40);
}

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

/* ----------------------------------------
   Toolbar Stack — stacks search + filter
   ---------------------------------------- */
.crud-toolbar-stack {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.875rem;
}

/* ----------------------------------------
   Search Bar — flat pill-style input
   ---------------------------------------- */
.crud-search-bar {
  display: flex;
  align-items: center;
  background: var(--crud-surface);
  border: 1.5px solid var(--crud-border);
  border-radius: var(--crud-radius-sm);
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  height: 42px;
  overflow: hidden;
  transition: border-color var(--crud-transition), box-shadow var(--crud-transition);
}

.crud-search-bar:focus-within {
  border-color: var(--hj-primary);
  box-shadow: 0 0 0 3px rgba(218,165,32,0.12), 0 1px 6px rgba(0,0,0,0.06);
  overflow: visible;
}

.crud-search-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 100%;
  flex-shrink: 0;
  font-size: 0.88rem;
  color: var(--crud-text-subtle);
  background: var(--crud-surface-2);
  border-right: 1.5px solid var(--crud-border-light);
  transition: color var(--crud-transition), background var(--crud-transition), border-color var(--crud-transition);
}

.crud-search-bar:focus-within .crud-search-icon {
  color: var(--hj-primary);
  background: #fffdf5;
  border-right-color: rgba(218,165,32,0.25);
}

.crud-search-form {
  flex: 1;
  display: flex;
  align-items: center;
  margin: 0;
  padding: 0;
  height: 100%;
}

.crud-search-fields {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.75rem;
  height: 100%;
  overflow: hidden;
}

.crud-search-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.875rem;
  color: var(--crud-text);
  padding: 0;
  height: 100%;
  box-shadow: none !important;
}

.crud-search-input::placeholder {
  color: var(--crud-text-subtle);
}

/* Remove browser native clear (X) on search inputs */
.crud-search-input[type="search"]::-webkit-search-cancel-button,
.crud-search-input[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.crud-search-date-range {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex: 1;
}

.crud-search-sep {
  color: var(--crud-text-subtle);
  font-size: 0.7rem;
  flex-shrink: 0;
}

.crud-search-actions {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0 0.5rem;
  flex-shrink: 0;
  height: 100%;
}

.crud-search-spinner {
  display: flex;
  align-items: center;
  color: var(--hj-primary);
}

.crud-clear-btn {
  width: 26px;
  height: 26px;
  border: none;
  background: transparent;
  color: var(--crud-text-subtle);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.75rem;
  transition: all var(--crud-transition);
  padding: 0;
  line-height: 1;
}

.crud-clear-btn:hover {
  background: var(--crud-surface-3);
  color: var(--hj-danger);
}

/* ----------------------------------------
   Filter Bar — New Responsive Design
   ---------------------------------------- */
.crud-filter-bar {
  display: flex;
  align-items: flex-start; /* Align to top for consistent wrapping */
  background: var(--crud-surface);
  border: 1.5px solid var(--crud-border);
  border-radius: var(--crud-radius-sm);
  padding: 0.5rem;
  gap: 0.5rem;
  margin-bottom: 0.875rem;
  flex-wrap: wrap; /* Allow wrapping on all screen sizes */
}

.crud-filter-bar-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 38px; /* Match form input height */
  padding: 0 0.75rem;
  color: var(--crud-text-muted);
  font-weight: 600;
  font-size: 0.875rem;
  gap: 0.5rem;
  white-space: nowrap;
}

.crud-filter-form {
  flex: 1 1 auto; /* Allow form to grow and shrink */
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem; /* Consistent gap for wrapped items */
  align-items: flex-start; /* Align wrapped items to the top */
}

/* Individual filter items within the form */
.crud-filter-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1 1 180px; /* Grow and shrink, with a base size */
  min-width: 160px; /* Prevent becoming too small */
}

/* Specific sizing for date ranges */
.crud-filter-item.filter-item-date-range {
  flex-basis: 200px;
}

.crud-filter-item .form-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--crud-text-muted);
  margin-bottom: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crud-filter-item .form-control,
.crud-filter-item .form-select,
.crud-filter-item .ts-wrapper .ts-control {
  height: 38px;
  font-size: 0.875rem;
  border-radius: var(--crud-radius-xs);
}

.crud-filter-item .input-group .form-control {
  height: 38px;
}

.crud-filter-item .input-group-text {
  height: 38px;
  border-radius: var(--crud-radius-xs) 0 0 var(--crud-radius-xs);
  font-size: 0.875rem;
}

/* Tom-select specific adjustments */
.crud-filter-item .ts-wrapper.single .ts-control,
.crud-filter-item .ts-wrapper.single .ts-control input {
  height: 38px;
}

.crud-filter-item .ts-wrapper .ts-control {
  border-radius: var(--crud-radius-xs);
  border-color: var(--crud-border);
}

.crud-filter-item .ts-wrapper.focus .ts-control {
  border-color: var(--hj-primary);
  box-shadow: 0 0 0 0.25rem rgba(var(--hj-primary-rgb), 0.25);
}

.crud-filter-bar .btn-submit-filter {
  height: 38px;
  align-self: flex-end; /* Align button to the bottom of its flex line */
}

/* Active Filters Bar */
.crud-active-filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
  padding: 0.5rem;
  background-color: var(--crud-surface-2);
  border-radius: var(--crud-radius-sm);
  border: 1px solid var(--crud-border-light);
}

.active-filter-pill {
  display: inline-flex;
  align-items: center;
  background-color: var(--crud-surface);
  border: 1px solid var(--crud-border);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--crud-text);
  white-space: nowrap;
}

.active-filter-pill .filter-label {
  color: var(--crud-text-muted);
  margin-right: 0.3rem;
}

.active-filter-pill .filter-value {
  font-weight: 600;
}

.crud-active-filters-bar .btn-outline-danger {
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
}

/* ----------------------------------------
   Mobile Filter Offcanvas
   ---------------------------------------- */
.crud-filter-offcanvas {
  max-height: 82vh;
  border-radius: 1.25rem 1.25rem 0 0;
  border: none;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.12);
}

.crud-filter-offcanvas .offcanvas-header {
  border-bottom: 1px solid var(--crud-border);
  padding: 1.125rem 1.25rem;
  background: var(--crud-surface-2);
  border-radius: 1.25rem 1.25rem 0 0;
}

.crud-filter-offcanvas .offcanvas-title {
  font-weight: 700;
  color: var(--crud-text);
  font-size: 1rem;
}

.crud-filter-offcanvas .offcanvas-body {
  padding: 1rem 1.25rem;
  overflow-y: auto;
}

.crud-filter-offcanvas .form-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--crud-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.35px;
}

.crud-filter-offcanvas .form-control,
.crud-filter-offcanvas .form-select {
  min-height: 44px;
  border: 1.5px solid var(--crud-border);
  border-radius: var(--crud-radius-xs);
}

.crud-filter-offcanvas .btn-primary {
  min-height: 50px;
  font-weight: 700;
  font-size: 1rem;
  border-radius: var(--crud-radius-sm);
}

/* ----------------------------------------
   Nested Item Cards — Mobile Form
   ---------------------------------------- */
.nested-item-card {
  border: 1px solid var(--crud-border);
  border-radius: var(--crud-radius-sm);
  transition: all var(--crud-transition);
  background: var(--crud-surface);
}

.nested-item-card:hover {
  border-color: var(--hj-primary-light);
  box-shadow: 0 2px 8px rgba(218, 165, 32, 0.10);
}

.nested-item-card .form-label-sm {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--crud-text-muted);
}

/* ----------------------------------------
   Responsive Breakpoints
   ---------------------------------------- */

/* ── Mobile < 768px ── */
@media (max-width: 767.98px) {

  /* Header */
  .crud-header {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
  }

  .crud-header h1 {
    font-size: 1.2rem;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Show */
  .crud-show-row {
    flex-direction: column;
  }

  .crud-show-label {
    flex: none;
    border-right: none;
    border-bottom: 1px solid var(--crud-border-light);
    padding: 0.625rem 1rem 0.3rem;
    font-size: 0.68rem;
  }

  .crud-show-value {
    padding: 0.375rem 1rem 0.75rem;
    font-size: 0.9rem;
  }

  .crud-show-card .card-header {
    padding: 1rem;
  }

  .crud-show-card .card-header h5 {
    font-size: 0.95rem;
  }

  /* Pagination */
  .crud-pagination {
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
  }

  .crud-pagination .page-link {
    width: 30px;
    height: 30px;
    font-size: 0.78rem;
  }

  /* Cards */
  .crud-search-card,
  .crud-filter-card {
    border-radius: var(--crud-radius-sm);
  }

  /* Form */
  .crud-form-card .card-body {
    padding: 1rem;
  }

  .crud-form-card .card-header {
    padding: 1rem 1.25rem;
  }

  /* Empty state */
  .crud-empty-state {
    padding: 2.5rem 1.25rem;
  }

  .crud-empty-state-icon {
    width: 68px;
    height: 68px;
  }

  .crud-empty-state-icon i {
    font-size: 1.6rem;
  }

  /* Tabs */
  .crud-tabs .nav-link {
    padding: 0.625rem 0.875rem;
    font-size: 0.82rem;
  }

  /* Content wrapper padding */
  .content-wrapper {
    padding: 0.75rem !important;
  }

  /* iOS-safe touch targets */
  .btn {
    min-height: 40px;
  }

  .form-control,
  .form-select {
    min-height: 44px;
    font-size: 16px; /* Prevents iOS zoom-on-focus */
  }

  .form-control-sm,
  .form-select-sm {
    min-height: 38px;
    font-size: 14px;
  }

  .crud-form-card .row > [class*="col-"] {
    margin-bottom: 0;
  }

  .nested-item-card .card-body {
    padding: 0.75rem;
  }
}

/* ── Tablet 768–991px ── */
@media (min-width: 768px) and (max-width: 991.98px) {

  .crud-show-label {
    flex: 0 0 175px;
    font-size: 0.75rem;
  }

  .crud-table thead th {
    font-size: 0.66rem;
    padding: 0.5rem 0.75rem;
  }

  .crud-table tbody td {
    font-size: 0.8rem;
    padding: 0.5rem 0.75rem;
  }
}

/* ── Large ≥ 1200px ── */
@media (min-width: 1200px) {

  .crud-table thead th {
    padding: 0.75rem 1.125rem;
  }

  .crud-table tbody td {
    padding: 0.75rem 1.125rem;
  }

  .crud-show-label {
    flex: 0 0 230px;
  }
}

/* ----------------------------------------
   CRUD Table & Card View — New Styles
   ---------------------------------------- */

/* Wrapper for both table and cards */
.crud-table-wrapper {
  background-color: var(--crud-surface);
  border-radius: var(--crud-radius);
  border: 1px solid var(--crud-border);
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--crud-shadow-sm);
}

/* Desktop Table Styles (≥ 768px) */
.crud-table {
  width: 100%;
  border-collapse: collapse;
}

.crud-table th,
.crud-table td {
  padding: 0.875rem 1.25rem;
  text-align: left;
  vertical-align: middle;
  font-size: 0.875rem;
  color: var(--crud-text);
}

.crud-table thead th {
  background-color: var(--crud-surface-2);
  font-weight: 600;
  color: var(--crud-text-muted);
  border-bottom: 2px solid var(--crud-border);
  white-space: nowrap;
}

.crud-table thead th a {
  color: inherit;
  text-decoration: none;
}

.crud-table thead th a:hover {
  color: var(--hj-primary, var(--crud-text));
}

.crud-table thead th .sort-icon {
  margin-left: 0.3rem;
  opacity: 0.6;
}

.crud-table tbody tr {
  border-bottom: 1px solid var(--crud-border-light);
  transition: background-color var(--crud-transition);
}

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

.crud-table tbody tr:hover {
  background-color: var(--crud-surface-2);
}

.crud-table .actions-cell {
  text-align: right;
  white-space: nowrap;
}

.crud-table .actions-cell .btn {
  margin-left: 0.25rem;
}

/* Mobile Card View Styles (< 768px) */
.crud-card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem;
  background-color: var(--crud-surface-2);
}

.crud-card-item {
  background-color: var(--crud-surface);
  border-radius: var(--crud-radius-sm);
  border: 1px solid var(--crud-border);
  box-shadow: var(--crud-shadow-sm);
  overflow: hidden;
  transition: all var(--crud-transition);
}

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

.crud-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background-color: var(--crud-surface-2);
  border-bottom: 1px solid var(--crud-border-light);
}

.crud-card-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--crud-text);
  margin: 0;
}

.crud-card-body {
  padding: 0.5rem 0;
}

.crud-card-field {
  display: flex;
  justify-content: space-between;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--crud-border-light);
}
.crud-card-field:last-child {
  border-bottom: none;
}

.crud-card-label {
  font-weight: 500;
  color: var(--crud-text-muted);
  margin-right: 1rem;
}

.crud-card-value {
  font-weight: 500;
  text-align: right;
}

.crud-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background-color: var(--crud-surface-2);
  border-top: 1px solid var(--crud-border-light);
}

/* ----------------------------------------
   Menu Permissions Table
   ---------------------------------------- */
.menu-permissions-table-wrap {
  overflow-x: auto;
  background: var(--crud-surface);
  border-radius: var(--crud-radius);
  border: 1px solid var(--crud-border);
  box-shadow: var(--crud-shadow-sm);
}

.menu-permissions-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
  background: transparent;
}

.menu-permissions-table thead th {
  background: var(--crud-surface-2);
  color: var(--crud-text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--crud-border);
}

.menu-permissions-table thead th.menu-permissions-role {
  text-align: center;
}

.menu-permissions-table tbody td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--crud-border-light);
  background: var(--crud-surface);
  vertical-align: middle;
}

.menu-permissions-table tbody tr:last-child td {
  border-bottom: 0;
}

.menu-permissions-table tbody tr:hover td {
  background: #fffdf5;
}

.menu-permissions-name {
  min-width: 260px;
}

.menu-permissions-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding-left: calc(var(--menu-depth, 0) * 1.25rem);
}

.menu-permissions-row.is-parent .menu-permissions-label {
  font-weight: 600;
  color: var(--crud-text);
}

.menu-permissions-row.is-child .menu-permissions-label {
  color: var(--crud-text-muted);
}

.menu-permissions-cell {
  text-align: center;
}

.menu-permissions-cell.is-disabled {
  opacity: 0.45;
}

.menu-permissions-input {
  margin: 0;
  cursor: pointer;
}

.menu-permissions-level-title {
  font-weight: 600;
  color: var(--crud-text);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--crud-border);
}
