/**
 * Table actions, Tailwind surface remaps, and html.dark utility maps (ticket 05 split).
 * Load order: immediately after overrides.css — see lattice_log/templates/base.html
 */

/* ============================================
   Table actions: sleek, premium, compact
   (every Actions column across the app)
   ============================================ */
.inventory-actions,
.table-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
/* Actions in a 2-column grid: consistent alignment across all tables */
.table-actions--grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.375rem 0.5rem;
  align-items: stretch;
  justify-items: stretch;
}
.table-actions--grid a,
.table-actions--grid button {
  min-width: 0;
}
.table-actions--grid a,
.table-actions--grid button {
  width: 100%;
}
.table-actions--grid form.inline {
  width: 100%;
  min-width: 0;
  display: block;
}
.table-actions--grid form.inline button {
  width: 100%;
}
.inventory-actions a,
.inventory-actions button,
.table-actions a,
.table-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  border-radius: 0.25rem;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
  text-decoration: none;
  min-width: 4rem;
  box-sizing: border-box;
}
.inventory-actions a:hover,
.inventory-actions button:hover,
.table-actions a:hover,
.table-actions button:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px -1px rgb(0 0 0 / 0.2);
}
.inventory-actions a:focus,
.inventory-actions button:focus,
.table-actions a:focus,
.table-actions button:focus {
  outline: none;
}
/* Compact icon-only row: single line, square buttons (inventory table) */
.table-actions--compact {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 0.25rem;
  align-items: center;
  width: auto;
}
.table-actions--compact a,
.table-actions--compact button {
  position: relative;
  width: 1.75rem;
  min-width: 1.75rem;
  height: 1.75rem;
  min-height: 1.75rem;
  padding: 0;
  border-radius: 0.25rem;
  flex-shrink: 0;
}
.table-actions--compact a svg,
.table-actions--compact button svg,
.table-actions--compact a .w-4,
.table-actions--compact a .h-4,
.table-actions--compact button .w-4,
.table-actions--compact button .h-4 {
  width: 0.875rem;
  height: 0.875rem;
}
/* Visually hide label; keep for screen readers and tooltips */
.table-actions--compact a span,
.table-actions--compact button span {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Actions cell: allow dropdown to extend outside without clipping */
td.table-actions-cell {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  overflow: visible;
  position: relative;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}
/* Split layout: primary button + kebab dropdown (sized to match row/panel) */
.table-actions--split {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.5rem;
  width: auto;
}
.table-actions--split .table-actions__primary {
  flex-shrink: 0;
  min-width: 0;
}
.table-actions--split .table-actions__primary a,
.table-actions--split .table-actions__primary button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.375rem 0.625rem;
  min-height: 36px;
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  border-radius: 0.375rem;
  text-decoration: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.table-actions--split .table-actions__primary a svg,
.table-actions--split .table-actions__primary a .w-4,
.table-actions--split .table-actions__primary a .h-4,
.table-actions--split .table-actions__primary button svg,
.table-actions--split .table-actions__primary button .w-4,
.table-actions--split .table-actions__primary button .h-4 {
  width: 1rem;
  height: 1rem;
}
.table-actions--split .table-actions__kebab {
  position: relative;
  flex-shrink: 0;
  z-index: 1;
}
/* When dropdown is open (Flowbite removes .hidden), lift above row dividers */
.table-actions--split .table-actions__kebab:focus-within,
.table-actions--split .table-actions__kebab:has(.table-actions__dropdown:not(.hidden)) {
  z-index: 10000;
}
.table-actions--split .table-actions__kebab-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 0.375rem;
  border: 1px solid rgb(var(--mdc-color-outline) / 0.4);
  background: rgb(var(--mdc-color-surface));
  color: rgb(var(--mdc-color-on-surface));
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.table-actions--split .table-actions__kebab-btn:hover {
  background: rgb(var(--mdc-color-outline) / 0.08);
  border-color: rgb(var(--mdc-color-outline) / 0.6);
}
.table-actions--split .table-actions__kebab-btn:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgb(var(--mdc-color-primary) / 0.4);
}
.table-actions--split .table-actions__kebab-btn svg,
.table-actions--split .table-actions__kebab-btn .w-4,
.table-actions--split .table-actions__kebab-btn .h-4 {
  width: 1.125rem;
  height: 1.125rem;
}
/* Inventory row detail mobile cards: primary fills width, kebab matches height */
.table-actions--row-mobile {
  width: 100%;
  gap: 0.5rem;
  align-items: stretch;
}
.table-actions--row-mobile .table-actions__primary {
  flex: 1 1 auto;
  min-width: 0;
}
.table-actions--row-mobile .table-actions__primary a,
.table-actions--row-mobile .table-actions__primary button {
  width: 100%;
  min-height: 44px;
}
.table-actions--row-mobile .table-actions__kebab-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
}

@media (max-width: 1023px) {
  .table-actions--split .table-actions__kebab-btn {
    width: var(--ll-touch-min, 44px);
    height: var(--ll-touch-min, 44px);
    min-width: var(--ll-touch-min, 44px);
    min-height: var(--ll-touch-min, 44px);
  }

  .table-actions--split .table-actions__primary a,
  .table-actions--split .table-actions__primary button {
    min-height: var(--ll-touch-min, 44px);
  }

  .table-actions__dropdown a,
  .table-actions__dropdown button {
    min-height: var(--ll-touch-min, 44px);
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
  }
}
/* Dropdown menu for table row actions: opaque so row dividers don’t show through */
.table-actions__dropdown {
  min-width: 7.5rem;
  max-height: var(--ll-dropdown-max-height, min(22rem, calc(100vh - 4rem)));
  padding: 0.125rem 0;
  border-radius: 0.375rem;
  border: 1px solid rgb(var(--mdc-color-outline) / 0.3);
  background-color: rgb(var(--mdc-color-surface));
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.2);
  z-index: 9999;
  isolation: isolate;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.table-actions__dropdown a,
.table-actions__dropdown button {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.375rem;
  width: 100%;
  min-width: 0;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  text-align: right;
  text-decoration: none;
  color: rgb(var(--mdc-color-on-surface));
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.1s ease;
}
.table-actions__dropdown a:hover,
.table-actions__dropdown button:hover {
  background: rgb(var(--mdc-color-outline) / 0.08);
  transform: none;
  box-shadow: none;
}
.table-actions__dropdown a.danger,
.table-actions__dropdown button.danger {
  color: rgb(var(--mdc-color-error));
}
.table-actions__dropdown form {
  display: block;
}
.table-actions__dropdown form button {
  width: 100%;
  justify-content: flex-end;
}
.table-actions__dropdown a svg,
.table-actions__dropdown button svg {
  flex: 0 0 1rem;
}
.table-actions__section-label {
  padding: 0.25rem 0.625rem 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: rgb(var(--mdc-color-on-surface) / 0.68);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.table-actions__dropdown .divider {
  height: 1px;
  margin: 0.125rem 0;
  background: rgb(var(--mdc-color-outline) / 0.2);
}
/* Match primary button size to kebab for visual balance */
.table-actions--split .table-actions__primary a,
.table-actions--split .table-actions__primary button {
  padding: 0.375rem 0.625rem;
  min-height: 36px;
}

/* Desktop: slimmer buttons for grid layouts */
@media (min-width: 640px) {
  .inventory-actions,
  .table-actions {
    gap: 0.375rem;
  }
  .inventory-actions a,
  .inventory-actions button,
  .table-actions a,
  .table-actions button {
    min-height: 28px;
    padding: 0.25rem 0.5rem;
  }
  .table-actions--grid a,
  .table-actions--grid button {
    min-height: 26px;
    padding: 0.25rem 0.375rem;
    font-size: 0.6875rem;
  }
  .inventory-actions a .w-4,
  .inventory-actions a .h-4,
  .inventory-actions a svg,
  .table-actions a .w-4,
  .table-actions a .h-4,
  .table-actions a svg,
  .table-actions button .w-4,
  .table-actions button .h-4,
  .table-actions button svg {
    width: 0.875rem;
    height: 0.875rem;
  }
}

.owner-clients-table-container {
  /* Smooth scrolling */
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Sticky first column for name */
html body [data-cy="platform-clients-table"] th:first-child,
html body [data-cy="platform-clients-table"] td:first-child {
  position: sticky;
  left: 0;
  z-index: 10;
  background-color: inherit;
}

html.dark [data-cy="platform-clients-table"] th:first-child,
html.dark [data-cy="platform-clients-table"] td:first-child {
  background-color: rgb(var(--mdc-color-surface));
}

/* Add shadow to sticky column when scrolled */
[data-cy="platform-clients-table"] th:first-child::after,
[data-cy="platform-clients-table"] td:first-child::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(to right, rgba(0,0,0,0.1), transparent);
  opacity: 0;
  transition: opacity 0.2s;
}

/* Dark mode: header uses green surface (forest-green theme, not slate) */
html.dark .app-header {
  background-color: rgb(var(--mdc-color-surface));
  border-bottom-color: rgb(var(--mdc-color-outline));
}
.header-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--ll-touch-min, 44px);
  min-width: var(--ll-touch-min, 44px);
  border-radius: 0.5rem;
  border: 1px solid rgb(var(--mdc-color-outline));
  background-color: rgb(var(--mdc-color-surface));
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.25rem;
  color: rgb(var(--mdc-color-on-surface));
  box-shadow: var(--mdc-shadow-sm);
  touch-action: manipulation;
}
.header-nav-btn:hover {
  border-color: rgb(var(--mdc-color-outline));
  background-color: rgb(var(--mdc-color-surface-hover));
}
.header-nav-btn:focus {
  outline: none;
}
.header-nav-btn:focus-visible {
  outline: 2px solid rgb(var(--mdc-color-primary));
  outline-offset: 2px;
}
html.dark .app-header .header-nav-btn {
  background-color: rgb(var(--mdc-color-surface));
  color: rgb(var(--mdc-color-on-surface));
  border-color: rgb(var(--mdc-color-outline));
}
html.dark .app-header .header-nav-btn:hover {
  background-color: rgb(var(--mdc-color-primary-container) / 0.35);
  border-color: rgb(var(--mdc-color-primary) / 0.25);
  color: rgb(var(--mdc-color-on-surface));
}

/* Dark mode: status badges – muted, non‑jarring (avoid bright pastel bg) */
html.dark [data-cy="status-badge"] {
  background-color: rgb(var(--mdc-color-surface));
  color: rgb(var(--mdc-color-on-surface));
  border: 1px solid rgb(var(--mdc-color-outline));
  box-shadow: none;
}
html.dark [data-cy="status-badge"]::before {
  border-color: transparent;
}
/* Subtle tint per status so badges stay distinguishable */
html.dark [data-cy="status-badge"][data-status-key="ready-for-sale"] {
  background-color: rgb(var(--mdc-color-primary-container) / 0.55);
  color: rgb(var(--mdc-color-on-primary-container));
  border-color: rgb(var(--mdc-color-outline));
}
html.dark [data-cy="status-badge"][data-status-key="planted"] {
  background-color: rgb(var(--mdc-color-status-planted-container));
  color: rgb(var(--mdc-color-on-status-planted));
  border-color: rgb(var(--mdc-color-outline));
}
html.dark [data-cy="status-badge"][data-status-key="dumped"] {
  background-color: rgb(var(--mdc-color-danger-container));
  color: rgb(var(--mdc-color-on-danger-container));
  border-color: rgb(var(--mdc-color-outline));
}
html.dark [data-cy="status-badge"][data-status-key="sold"] {
  background-color: rgb(var(--mdc-color-status-sold-container));
  color: rgb(var(--mdc-color-on-status-sold));
  border-color: rgb(var(--mdc-color-outline));
}
html.dark [data-cy="status-badge"][data-status-key="archived"],
html.dark [data-cy="status-badge"][data-status-key="active"] {
  background-color: rgb(var(--mdc-color-surface));
  color: rgb(var(--mdc-color-on-surface));
  border-color: rgb(var(--mdc-color-outline));
}

/* Dark mode: pagination "Show X per page" – readable text and select */
html.dark .pagination-per-page select.pagination-per-page-select {
  background-color: rgb(var(--mdc-color-surface));
  color: rgb(var(--mdc-color-on-surface));
  border-color: rgb(var(--mdc-color-outline));
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3E%3C/svg%3E");
}
html.dark .pagination-per-page {
  color: rgb(var(--mdc-color-on-surface));
}

/* Dark mode: form fields using .form-control (see Section 5 owners) */
html.dark .form-control {
  background-color: rgb(var(--mdc-color-surface)); /* reason: override Tailwind bg-* on inputs */
  color: rgb(var(--mdc-color-on-surface));
  border-color: rgb(var(--mdc-color-outline));
}
html.dark .form-control::placeholder {
  color: rgb(var(--mdc-color-on-surface-muted));
}
html.dark .form-control[readonly] {
  background-color: rgb(var(--mdc-color-input-readonly-bg));
}
html.dark .form-control.invalid:not(:focus),
html.dark .form-control.is-invalid:not(:focus),
html.dark .form-control[aria-invalid="true"]:not(:focus) {
  border-color: rgb(var(--mdc-color-error));
  background-color: rgb(var(--mdc-color-input-error-bg));
}
html.dark .form-control:focus:not(:disabled) {
  border-color: rgb(var(--mdc-color-input-border-focus));
  box-shadow: 0 0 0 2px rgb(var(--mdc-focus-ring-input) / var(--mdc-input-focus-ring-opacity));
}
html.dark .form-control.invalid:focus,
html.dark .form-control.is-invalid:focus,
html.dark .form-control[aria-invalid="true"]:focus {
  border-color: rgb(var(--mdc-color-error));
  box-shadow: 0 0 0 2px rgb(var(--mdc-color-error) / 0.38);
}

/* Dark mode gradient overrides – replace white gradient stops with surface color */
html.dark .from-white {
  --tw-gradient-from: rgb(var(--mdc-color-surface));
  --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to);
}
html.dark .via-white {
  --tw-gradient-stops: var(--tw-gradient-from), rgb(var(--mdc-color-surface)), var(--tw-gradient-to);
}
html.dark .to-white {
  --tw-gradient-to: rgb(var(--mdc-color-surface));
}
