/* Phase A — mobile-first UX (dinod theme) */

/* --- Header search (collapsible on mobile) --- */
.header-search-wrap {
  display: flex;
  align-items: center;
  flex: 1;
  max-width: 420px;
  min-width: 0;
}

.sm-header-search-toggle {
  display: none;
  background: rgba(65, 224, 253, 0.15);
  border: 1px solid rgba(65, 224, 253, 0.35);
  border-radius: 8px;
  color: var(--sm-accent-primary, #41e0fd);
  padding: 0.45rem 0.65rem;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
}

.header-search {
  flex: 1;
  width: 100%;
}

@media (max-width: 768px) {
  .sm-header-search-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .header-search {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    padding: 0.75rem 1rem;
    background: rgba(18, 22, 28, 0.98);
    border-bottom: 1px solid rgba(65, 224, 253, 0.25);
    z-index: 50;
    margin: 0;
    max-width: none;
  }

  .header-search.is-open {
    display: block;
  }

  .main-header {
    margin-bottom: 1rem;
  }

  .container-header {
    position: relative;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
}

/* --- Homepage hub (logged-out / simplified) --- */
.homepage-actions--primary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.homepage-actions--secondary details {
  margin-bottom: 1rem;
}

.homepage-more-summary {
  list-style: none;
  cursor: pointer;
  padding: 0.85rem 1rem;
  background: rgba(34, 40, 50, 0.6);
  border: 1px solid rgba(65, 224, 253, 0.25);
  border-radius: 10px;
  color: var(--sm-accent-primary, #41e0fd);
  font-weight: 600;
  min-height: 44px;
}

.homepage-more-summary::-webkit-details-marker {
  display: none;
}

.homepage-more-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  padding: 0.75rem 0 0;
}

@media (max-width: 600px) {
  .homepage-actions--primary {
    grid-template-columns: 1fr;
  }

  .homepage-more-grid {
    grid-template-columns: 1fr;
  }
}

/* --- Homepage post cards (clickable title + image) --- */
.post-card .post-info h3 a {
  color: inherit;
  text-decoration: none;
}

.post-card .post-info h3 a:hover {
  color: var(--sm-accent-primary, #41e0fd);
}

.post-card > a {
  display: block;
  line-height: 0;
}

/* --- Stack tables → cards on mobile --- */
@media (max-width: 768px) {
  #spoolman-table,
  #spoolman-archived-table,
  #parts-table,
  #wishlist-items-table,
  #gadgets-table,
  #price-comparison-table {
    min-width: 0 !important;
    width: 100% !important;
    table-layout: auto !important;
  }

  .table-container:has(.sm-stack-table),
  .spoolman-table-wrapper:has(.sm-stack-table),
  .dataTables_wrapper:has(.sm-stack-table),
  .dataTables_scroll,
  .dataTables_scrollBody,
  .dataTables_scrollHead {
    overflow: visible !important;
    width: 100% !important;
  }

  .sm-stack-table thead,
  .sm-stack-table tfoot {
    display: none !important;
  }

  .sm-stack-table,
  .sm-stack-table tbody {
    display: block !important;
    width: 100% !important;
  }

  /* Override fixed row heights from style.css */
  .sm-stack-table tbody tr,
  .spoolman-table-wrapper .sm-stack-table tbody tr,
  #spoolman-table.sm-stack-table tbody tr,
  #spoolman-archived-table.sm-stack-table tbody tr,
  #parts-table.sm-stack-table tbody tr,
  #wishlist-items-table.sm-stack-table tbody tr,
  #gadgets-table.sm-stack-table tbody tr {
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin-bottom: 0.85rem;
    padding: 0.85rem 1rem;
    background: rgba(24, 30, 40, 0.92);
    border: 1px solid rgba(65, 224, 253, 0.22);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  }

  .sm-stack-table tbody td,
  table#parts-table.sm-stack-table tbody td,
  #spoolman-table.sm-stack-table tbody td,
  #wishlist-items-table.sm-stack-table tbody td {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    position: static !important;
    padding: 0.55rem 0 !important;
    border: none !important;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12) !important;
    text-align: left !important;
    font-size: 0.95rem;
    white-space: normal !important;
    vertical-align: top !important;
  }

  table#parts-table.sm-stack-table tbody td:not(:last-child) .cell-content-wrapper {
    display: block !important;
    -webkit-line-clamp: unset !important;
    -webkit-box-orient: unset !important;
    max-height: none !important;
    overflow: visible !important;
    line-height: 1.45 !important;
  }

  #wishlist-items-table.sm-stack-table tbody td:not(:last-child)::after {
    display: none !important;
  }

  .sm-stack-table tbody td:last-child {
    border-bottom: none !important;
    padding-top: 0.65rem !important;
  }

  .sm-stack-table tbody td::before {
    content: attr(data-label);
    display: block;
    font-weight: 600;
    color: rgba(65, 224, 253, 0.85);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.2rem;
  }

  .sm-stack-table tbody td[data-label='']::before,
  .sm-stack-table tbody td:not([data-label])::before {
    display: none;
  }

  /* Hide low-value columns on small screens */
  .sm-stack-table tbody td[data-label='ID'],
  .sm-stack-table tbody td[data-label='Comment'],
  .sm-stack-table tbody td[data-label='Dimensions'] {
    display: none !important;
  }

  /* Spool / part title rows */
  #spoolman-table.sm-stack-table tbody td[data-label='Filament'],
  #spoolman-archived-table.sm-stack-table tbody td[data-label='Filament'] {
    font-size: 1.08rem;
    font-weight: 600;
    border-bottom: 2px solid rgba(65, 224, 253, 0.2) !important;
    padding-bottom: 0.65rem !important;
    margin-bottom: 0.15rem;
  }

  #spoolman-table.sm-stack-table tbody td[data-label='Filament']::before,
  #spoolman-archived-table.sm-stack-table tbody td[data-label='Filament']::before {
    display: none;
  }

  #parts-table.sm-stack-table tbody td[data-label='Part'] {
    font-size: 1.08rem;
    font-weight: 600;
    border-bottom: 2px solid rgba(65, 224, 253, 0.2) !important;
  }

  #parts-table.sm-stack-table tbody td[data-label='Part']::before {
    display: none;
  }

  /* Actions row */
  .sm-stack-table tbody td[data-label='Actions'] {
    display: flex !important;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
  }

  .sm-stack-table tbody td[data-label='Actions']::before {
    width: 100%;
  }

  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter {
    width: 100%;
  }

  .dataTables_wrapper .dataTables_filter input {
    min-height: 44px;
    font-size: 16px;
  }
}

/* --- Bottom nav + safe area --- */
.sm-mobile-bottom-nav {
  padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
}

.sm-mobile-nav-item.is-active {
  color: var(--sm-accent-primary, #41e0fd);
}

.sm-mobile-nav-item.is-active svg {
  filter: drop-shadow(0 0 6px rgba(65, 224, 253, 0.5));
}

@media (max-width: 768px) {
  main,
  .homepage-main,
  .spoolman-main-page {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
  }

  footer[role='contentinfo'] {
    padding-bottom: calc(4rem + env(safe-area-inset-bottom, 0px));
  }
}

/* --- More drawer --- */
.sm-mobile-more-drawer {
  position: fixed;
  inset: 0;
  z-index: 1100;
  pointer-events: none;
  visibility: hidden;
  transition: visibility 0.25s;
}

.sm-mobile-more-drawer.is-open {
  pointer-events: auto;
  visibility: visible;
}

.sm-mobile-more-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.25s;
}

.sm-mobile-more-drawer.is-open .sm-mobile-more-backdrop {
  opacity: 1;
}

.sm-mobile-more-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 70vh;
  overflow-y: auto;
  background: rgba(18, 22, 28, 0.98);
  border-top: 1px solid rgba(65, 224, 253, 0.35);
  border-radius: 16px 16px 0 0;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform 0.28s ease-out;
}

.sm-mobile-more-drawer.is-open .sm-mobile-more-panel {
  transform: translateY(0);
}

.sm-mobile-more-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.sm-mobile-more-header h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--sm-accent-primary, #41e0fd);
}

.sm-mobile-more-close {
  background: none;
  border: none;
  color: #e0eefd;
  font-size: 1.5rem;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
}

.sm-mobile-more-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.sm-mobile-more-links a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  background: rgba(34, 40, 50, 0.8);
  border: 1px solid rgba(65, 224, 253, 0.2);
  border-radius: 10px;
  color: #e0eefd;
  text-decoration: none;
  font-weight: 500;
  min-height: 44px;
}

body.sm-drawer-open {
  overflow: hidden;
}

/* --- FAB --- */
.sm-mobile-fab {
  display: none;
  position: fixed;
  right: 1rem;
  bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
  z-index: 1050;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

@media (max-width: 768px) {
  .sm-mobile-fab.sm-mobile-fab--visible {
    display: flex;
  }
}

.sm-mobile-fab-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #41e0fd, #22d3ee);
  color: #04161b;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(65, 224, 253, 0.45);
}

.sm-mobile-fab-menu {
  display: none;
  flex-direction: column;
  gap: 0.35rem;
  align-items: flex-end;
}

.sm-mobile-fab.is-open .sm-mobile-fab-menu {
  display: flex;
}

.sm-mobile-fab-action {
  padding: 0.65rem 1rem;
  background: rgba(24, 30, 40, 0.95);
  border: 1px solid rgba(65, 224, 253, 0.35);
  border-radius: 999px;
  color: #e0eefd;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

/* --- Sticky form actions (thumb zone) --- */
@media (max-width: 768px) {
  .sm-form-actions-sticky,
  .filament-form-main .btn--primary[type='submit'],
  .part-detail-wrap form .btn--primary:last-of-type,
  #sm-set-reorder-point-form .btn--primary {
    position: sticky;
    bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
    z-index: 40;
    width: 100%;
    min-height: 48px;
    margin-top: 0.5rem;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.35);
  }

  .btn,
  .sm-action-btn,
  .add-wishlist-btn {
    min-height: 44px;
  }
}
