/**
 * Unified container and row styling for Search Insights
 * This creates consistent appearance across all plugin sections:
 * - Dashboard widget
 * - Popular searches
 * - Analytics blocks
 * - Trending searches
 */

@import "colors";
@import "font-sizes";

// Unified container for all row collections
.wpsi-row-container {
  border-radius: 4px;
  margin-bottom: 20px;

  // Container header styling
  .wpsi-container-header {
    font-size: @font-size-large;
    color: @table-head-text-color;
    font-weight: 600;
  }

  // Container for actual rows
  .wpsi-rows-wrap {
    max-height: 400px;
    overflow-y: auto;

    // Nice scrollbar styling
    &::-webkit-scrollbar {
      width: 8px;
    }

    &::-webkit-scrollbar-track {
      background: #f1f1f1;
    }

    &::-webkit-scrollbar-thumb {
      background: #cdcdcd;
      border-radius: 4px;
    }

    &::-webkit-scrollbar-thumb:hover {
      background: #aaa;
    }
  }
}

// Row styling (from previous implementation)
.wpsi-search-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 15px;
  border-bottom: 1px solid @border-color;
  background-color: @background-color;
  transition: background-color 0.2s ease;

  &:last-child {
    border-bottom: none;
  }

  // Add alternating row colors like tables
  &:nth-child(even) {
    background-color: @even-row-color;
  }

  &:nth-child(odd) {
    background-color: @odd-row-color;
  }

  &:hover {
    //background-color: #f8f8f8;
  }

  .dashicons-yes-alt {
    color: @color-success;
    font-size: 16px;
  }

  .dashicons-no-alt {
    color: @color-error;
    font-size: 16px;
  }

  &.wpsi-has-results {
    .wpsi-row-term a {
      color: @color-success;
    }
  }

  &.wpsi-no-results {
    .wpsi-row-term a {
      color: @color-error;
    }
  }

  // Left side term styling
  .wpsi-row-term {
    display: flex;
    align-items: center;
    max-width: 70%;
    overflow: hidden;
    font-size: @font-size-small;

    .dashicons {
      margin-right: 8px;
      display: flex;
      align-items: center;

      &.dashicons-arrow-up-alt {
        color: @color-success;
      }

      &.dashicons-arrow-down-alt {
        color: @color-success;
      }
    }

    a {
      text-decoration: none;
      color: @text-color;
      transition: color 0.2s ease;

      &:hover {
        color: @brand-primary;
      }

      // Preserve the ellipsis behavior for long text
      &.wpsi-ellipsis {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }

    .wpsi-status {
      display: flex;
      align-items: center;

      &.wpsi-status-success {
        color: @color-success;

        .dashicons {
          color: @color-success;
        }
      }

      &.wpsi-status-abandoned {
        color: @color-error;

        .dashicons {
          color: @color-error;
        }
      }

      &.wpsi-status-active {
        color: @wpsi-blue;

        .dashicons {
          color: @wpsi-blue;
        }
      }

      &.wpsi-status-exit,
      &.wpsi-status-none {
        color: @color-error;

        .dashicons {
          color: @color-error;
        }
      }
    }
  }

  // Right side stats styling
  .wpsi-row-stats {
    display: flex;
    align-items: center;
    text-align: right;
    color: @text-color;
    font-size: @font-size-small;

    > span {
      margin-left: 15px;
      white-space: nowrap;
    }

    .wpsi-stat-trend {
      min-width: 60px;
      text-align: right;
      overflow: clip;
    }
  }
}

// Ensure old containers use new styling
.wpsi-analytics-container .wpsi-results-column,
#wpsi-dashboard-widget,
.wpsi-dashboard-widget-grid,
.wpsi-item .table-overview {
  &:extend(.wpsi-row-container);

  // Add headers for old containers
  > h3 {
    &:extend(.wpsi-row-container .wpsi-container-header);
  }

  // Add scrollable container for old wrappers
  .wpsi-popular-results,
  ul,
  tbody {
    &:extend(.wpsi-row-container .wpsi-rows-wrap);
  }
}

// Add table-specific styles to match the row styling
// Only apply to dashboard class not settings
#dashboard.tab-content .item-content table,
.wpsi-trending-container .wpsi-trending-table {
  // Apply to tbody rows only, not thead
  tbody tr {
    transition: background-color 0.2s ease;

    &:hover {
      background-color: #f8f8f8 !important;
    }

    // Alternating row colors for tables
    &:nth-child(even) td {
      background-color: @even-row-color;
    }

    &:nth-child(odd) td {
      background-color: @odd-row-color;
    }
  }

  // Apply link styling
  td a {
    color: @text-color;
    text-decoration: none;
    transition: color 0.2s ease;

    &:hover {
      color: @brand-primary;
    }
  }
}

// Container layout system for side-by-side containers
.wpsi-container-layout {
  display: flex;
  gap: 30px;
  margin: 20px 0;

  // Equal width columns by default
  .wpsi-row-container {
    flex: 1;
    min-width: 0; // Prevents flex items from overflowing
  }

  // Optional column sizing classes
  .wpsi-col-2-3 {
    flex: 2;
  }

  .wpsi-col-1-3 {
    flex: 1;
  }

  .wpsi-col-1-2 {
    flex: 1;
  }

  // Responsive behavior
  @media screen and (max-width: 1024px) {
    gap: 20px;
  }

  @media screen and (max-width: 768px) {
    flex-direction: column;
    gap: 20px;

    .wpsi-row-container {
      width: 100%;
    }
  }
}

// Responsive adjustments
@media screen and (max-width: 768px) {
  .wpsi-row-container {
    .wpsi-container-header {
      padding: 12px;
    }
  }

  .wpsi-search-row {
    padding: 8px 12px;

    .wpsi-row-term {
      max-width: 65%;
    }

    .wpsi-row-stats > span {
      margin-left: 10px;
    }
  }
}

@media screen and (max-width: 480px) {
  .wpsi-row-container {
    .wpsi-container-header {
      padding: 10px;
    }
  }

  .wpsi-search-row {
    padding: 8px 10px;

    .wpsi-row-term {
      max-width: 60%;
    }

    .wpsi-row-stats {
      flex-direction: column;
      align-items: flex-end;

      > span {
        margin-left: 0;
        margin-bottom: 3px;
        font-size: @font-size-xs;
      }
    }
  }
}

// Hide tooltips in WordPress dashboard widget
#dashboard-widgets #wpsi-dashboard-widget {
  .wpsi-container-header,
  .wpsi-container-title {
    .dashicons-editor-help {
      display: none !important;
    }

    .wpsi-tooltip-right,
    .wpsi-tooltip-bottom,
    [data-wpsi-tooltip] {
      &:before, &:after {
        display: none !important;
      }
    }
  }
}

// In case tooltips appear in search rows within dashboard widget
#dashboard-widgets #wpsi-dashboard-widget .wpsi-search-row {
  .wpsi-tooltip-right,
  .wpsi-tooltip-bottom,
  [data-wpsi-tooltip] {
    &:before, &:after {
      display: none !important;
    }
  }
}

// Ensure backward compatibility with li elements in dashboard widgets
.wpsi-dashboard-list {
  margin: 0;
  padding: 0;
  list-style: none;

  // Make divs look like list items for backward compatibility
  .wpsi-search-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid @border-color;
    margin: 0;

    &:last-child {
      border-bottom: none;
    }

    &.dashboard-row, &.grid-row {
      // Additional styles specific to dashboard rows
    }
  }
}
