/**
 * 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;
}
/* 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;
  }
}
/* Tailwind “white” utilities appear throughout templates; tint them green. */
.bg-white {
  background-color: var(--surface);
}
.bg-white\/90 {
  background-color: var(--surface-90);
}
.bg-white\/80 {
  background-color: var(--surface-80);
}
.bg-white\/70 {
  background-color: var(--surface-70);
}
.bg-white\/60 {
  background-color: var(--surface-60);
}
.bg-white\/50 {
  background-color: var(--surface-50);
}
.hover\:bg-white:hover {
  background-color: var(--surface);
}

/* Common near-white “neutral” backgrounds → green-tinted too. */
.bg-slate-50 {
  background-color: rgb(var(--mdc-color-background) / 0.65);
}
.bg-slate-100 {
  background-color: rgb(var(--mdc-color-primary-container) / 0.55);
}
.hover\:bg-slate-50:hover {
  background-color: rgb(var(--mdc-color-background) / 0.85);
}
.hover\:bg-slate-100:hover {
  background-color: rgb(var(--mdc-color-primary-container) / 0.75);
}

/* Dark mode overrides for gray table headers */
html.dark .bg-gray-50 {
  background-color: rgb(var(--mdc-color-surface));
}
html.dark .bg-gray-100 {
  background-color: rgb(var(--mdc-color-primary-container) / 0.55);
}

/* Dark mode hover states */
html.dark .hover\:bg-slate-100:hover {
  background-color: rgb(var(--mdc-color-primary-container) / 0.75);
}

html.dark .hover\:bg-gray-50:hover {
  background-color: rgb(var(--mdc-color-primary-container) / 0.55);
}

/* Dark mode: emerald utility classes mapped to primary tokens */
html.dark .bg-emerald-50 {
  background-color: rgb(var(--mdc-color-primary-container) / 0.5);
}

html.dark .border-emerald-200 {
  border-color: rgb(var(--mdc-color-primary) / 0.3);
}

html.dark .text-emerald-700 {
  color: rgb(var(--mdc-color-primary));
}

html.dark .text-emerald-900 {
  color: rgb(var(--mdc-color-on-surface));
}

html.dark .text-emerald-600 {
  color: rgb(var(--mdc-color-primary));
}

html.dark .border-emerald-600 {
  border-color: rgb(var(--mdc-color-primary));
}

html.dark .bg-emerald-600 {
  background-color: rgb(var(--mdc-color-primary));
}

html.dark .hover\:bg-emerald-700:hover {
  background-color: rgb(var(--mdc-color-primary-hover));
}

/* Dark mode for blue inventory depth highlights */
html.dark .text-blue-700 {
  color: rgb(139, 193, 232); /* Lighter blue for dark mode */
}

html.dark .text-blue-600 {
  color: rgb(139, 193, 232); /* Lighter blue for dark mode */
}

/* Dark mode for white stat cards */
html.dark .bg-white {
  background-color: rgb(var(--mdc-color-surface));
}

html.dark .border-slate-200 {
  border-color: rgb(var(--mdc-color-outline) / 0.3);
}

/* Dark mode for badge styles */
html.dark .bg-amber-100 {
  background-color: rgb(217, 119, 6, 0.2); /* amber-600 with opacity */
}

html.dark .text-amber-800 {
  color: rgb(252, 211, 77); /* amber-300 */
}

html.dark .bg-slate-100 {
  background-color: rgb(var(--mdc-color-primary-container) / 0.45);
}

html.dark .text-slate-700 {
  color: rgb(var(--mdc-color-on-surface-muted));
}

/* Dark mode for tab navigation and borders */
html.dark .hover\:border-emerald-300:hover {
  border-color: rgb(var(--mdc-color-primary) / 0.5);
}

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

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

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

/* Add shadow to sticky column when scrolled */
[data-cy="owner-clients-table"] th:first-child::after,
[data-cy="owner-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 text color overrides – ensure adequate contrast on dark surfaces. */
html.dark {
  /* Map common Tailwind slate text utilities to on-surface tokens. */
  --_on-surface: rgb(var(--mdc-color-on-surface));
  --_on-surface-muted: rgb(var(--mdc-color-on-surface-muted));
}

html.dark .text-slate-900,
html.dark .text-slate-800,
html.dark .text-slate-700,
html.dark .text-gray-900,
html.dark .text-gray-800,
html.dark .text-gray-700 {
  color: var(--_on-surface);
}

html.dark .text-slate-600,
html.dark .text-slate-500,
html.dark .text-slate-400,
html.dark .text-gray-600,
html.dark .text-gray-500,
html.dark .text-gray-400 {
  color: var(--_on-surface-muted);
}

/* Adjust border utilities to use outline token for sufficient contrast */
html.dark .border-slate-200,
html.dark .border-slate-300,
html.dark .border-slate-400,
html.dark .border-gray-200,
html.dark .border-gray-300,
html.dark .border-gray-400 {
  border-color: rgb(var(--mdc-color-outline));
}

/* Override ring colors that are hard to see in dark mode */
html.dark .ring-slate-200,
html.dark .ring-slate-300 {
  --tw-ring-color: rgb(var(--mdc-color-outline) / var(--tw-ring-opacity, 1));
}

/* 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;
  border-radius: 0.5rem;
  border: 1px solid rgb(226 232 240);
  background-color: rgb(255 255 255);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.25rem;
  color: rgb(51 65 85);
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.08);
}
.header-nav-btn:hover {
  border-color: rgb(203 213 225);
  background-color: rgb(248 250 252);
}
.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(20 83 45 / 0.5);
  color: rgb(167 243 208);
  border-color: rgb(36 69 52);
}
html.dark [data-cy="status-badge"][data-status-key="planted"] {
  background-color: rgb(14 116 144 / 0.35);
  color: rgb(165 243 252);
  border-color: rgb(36 69 52);
}
html.dark [data-cy="status-badge"][data-status-key="budded"] {
  background-color: rgb(3 105 161 / 0.35);
  color: rgb(186 230 253);
  border-color: rgb(36 69 52);
}
html.dark [data-cy="status-badge"][data-status-key="cracking-color"] {
  background-color: rgb(146 64 14 / 0.35);
  color: rgb(254 215 170);
  border-color: rgb(36 69 52);
}
html.dark [data-cy="status-badge"][data-status-key="dumped"] {
  background-color: rgb(91 33 182 / 0.35);
  color: rgb(221 214 254);
  border-color: rgb(36 69 52);
}
html.dark [data-cy="status-badge"][data-status-key="sold"] {
  background-color: rgb(159 18 57 / 0.35);
  color: rgb(254 205 211);
  border-color: rgb(36 69 52);
}
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 #per-page-select {
  background-color: rgb(var(--mdc-color-surface));
  color: rgb(var(--mdc-color-on-surface));
  border-color: rgb(var(--mdc-color-outline));
}
html.dark .pagination-per-page .text-slate-600,
html.dark .pagination-per-page .text-slate-700 {
  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));
}
