@use 'variables';
@use 'sass:color';

// Mobile-first responsive layout fixes
body.ambi-page {
    #wpcontent {
        padding-left: 0 !important;
    }

    // Fix WordPress admin bar overlap on mobile (default mobile styles)
    &.admin-bar #wpcontent {
        padding-top: 46px; // WordPress mobile admin bar height
    }

    // Ensure no negative margins that could cause overlap
    #wpbody {
        margin-top: 0;
        padding-top: 0;
    }

    // Desktop adjustments
    @media (min-width: 601px) {
        &.admin-bar #wpcontent {
            padding-top: 0;
        }
    }
}

#ambi-header {
    font-size: 1rem;
    line-height: 1.2;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 1rem;
    background: variables.$color-black;
    color: #fff;
    gap: 1rem;
    position: relative;
    z-index: 100;
    flex-wrap: wrap;

    .ambi-header {
        flex: 1;
        min-width: 100%;
        justify-content: center;

        &__logo {
            font-size: 1.1rem;
        }
    }

    .ambi-nav {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.25rem;

        &__link {
            padding: 0.375rem 0.75rem;
            font-size: 0.8rem;
        }
    }

    // Desktop header adjustments
    @media (min-width: 783px) {
        padding: 1.5rem;
        gap: 1.5rem;
        flex-wrap: nowrap;

        .ambi-header {
            flex: 0;
            min-width: auto;
            justify-content: flex-start;

            &__logo {
                font-size: 1.5rem;
            }
        }

        .ambi-nav {
            width: auto;
            justify-content: flex-start;
            flex-wrap: nowrap;
            gap: 0.5rem;

            &__link {
                padding: 0.5rem 1rem;
                font-size: 0.9rem;
            }
        }
    }
}

#ambi-page {
    padding: 1rem;
    margin-top: 0;

    // Desktop page adjustments
    @media (min-width: 783px) {
        padding: 1.5rem;
    }

  // Enhanced filter form styling
  form.alignleft {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
  }

  // Table navigation styling - mobile first
  .tablenav {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 0.375rem 0;
    margin: 0.375rem 0;
    height: auto;
    gap: 0.5rem;

    &.top {
      border-bottom: 1px solid #ddd;
    }

    br.clear {
      display: none;
    }

    .actions {
      width: 100%;
      margin-right: 0;
      margin-bottom: 0.5rem;
      min-width: 0;
      order: 1;
      min-width: 280px;
      display: block;
    }

    .bulkactions {
      display: none;
      flex: 1;
      margin-right: 0;
      margin-bottom: 0.5rem;
      min-width: 0;
      order: 1;
      min-width: 200px;
    }

    .tablenav-pages {
      width: 100%;
      justify-content: flex-end;
      order: 2;
      margin-left: 0;
      flex: 0 0 auto;
      white-space: nowrap;
      display: flex;
      float: none;
      align-items: center;
      gap: 0.5rem;
      margin: 0;
      text-align: right;
      min-width: 200px;
      flex-wrap: nowrap;

      .displaying-num {
        font-size: 0.7rem;
      }

      .pagination-links .button {
        padding: 0.125rem 0.375rem;
        font-size: 0.75rem;
        min-width: 1.5rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        line-height: 1;

        &:not(.disabled):hover {
          background: #e6e6e6;
          border-color: #999;
          color: #333;
        }

        &.disabled {
          opacity: 0.5;
          cursor: not-allowed;
        }
      }

      .paging-input .current-page {
        width: 2rem;
        font-size: 0.7rem;
      }
    }

    // Desktop table navigation adjustments
    @media (min-width: 783px) {
      padding: 0.5rem 0;
      margin: 0.5rem 0;
      gap: 0;

      .actions {
        width: auto;
        flex: 1;
        margin-bottom: 0;
        min-width: 0;
        display: block;
      }

      .tablenav-pages {
        width: auto;
        justify-content: flex-end;
        margin-left: auto;

        .displaying-num {
          font-size: 0.75rem;
        }

        .pagination-links .button {
          padding: 0.125rem 0.375rem;
          font-size: 0.75rem;
          min-width: 1.5rem;
        }

        .paging-input .current-page {
          width: 2.5rem;
          font-size: 0.75rem;
        }
      }
    }
  }

  // Advanced filter form styling - mobile first
  .ambi-filters-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.3rem;
    margin: 0;

    .ambi-filter-group {
      display: flex;
      flex-direction: column;
      gap: 0.2rem;
      flex: 0 1 auto;
      position: relative;
    }

    .ambi-filter-label {
      font-size: 0.65rem;
      font-weight: 500;
      color: #666;
      margin: 0;
      white-space: nowrap;
      text-transform: uppercase;
      letter-spacing: 0.02em;
      position: absolute;
      top: -1.2rem;
      left: 0;
      z-index: 1;

      // Hide labels on mobile to save space
      @media (max-width: 782px) {
        display: none;
      }
    }

    .ambi-filter {
      padding: 0 0.4rem;
      border: 1px solid #ddd;
      border-radius: 3px;
      font-size: 0.75rem;
      transition: border-color 0.15s ease-in-out;
      min-height: 44px;
      line-height: 1.2;
      box-sizing: border-box;

      &:focus {
        outline: none;
        border-color: #0073aa;
        box-shadow: 0 0 0 1px #0073aa;
      }

      &--date-from,
      &--date-to {
        width: 110px;
      }

      &--user,
      &--entity-type {
        width: 85px;
      }

      &--action,
      &--event-type {
        width: 95px;
      }

      &--entity-id {
        width: 80px;
      }
    }

    // Select elements specific styling for text truncation
    select.ambi-filter {
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
      padding-right: 1.2rem; // Space for dropdown arrow
    }

    .ambi-filter-buttons {
      display: flex;
      align-items: flex-end;
      gap: 0.25rem;
      flex-shrink: 0;
    }

    .ambi-filter-button {
      padding: 0 0.6rem;
      font-size: 0.75rem;
      border-radius: 3px;
      text-decoration: none;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      transition: all 0.15s ease-in-out;
      min-height: 44px;
      line-height: 1.2;
      box-sizing: border-box;
      border: 1px solid transparent;
      white-space: nowrap;
      flex: 0 0 auto;
      gap: 0.25rem;
      margin:0;
      .dashicons {
        font-size: 16px;
        width: 16px;
        height: 16px;
        line-height: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        margin: 0;
      }

      &--submit {
        background: variables.$color-primary;
        border-color: variables.$color-primary;
        color: variables.$color-black;

        &:hover {
          background: color.adjust(variables.$color-primary, $lightness: 10%);
          border-color: color.adjust(variables.$color-primary, $lightness: 10%);
        }
      }

      &--clear {
        background: #f1f1f1;
        border: 1px solid #ddd;
        color: #666;

        &:hover {
          background: #e6e6e6;
          border-color: #999;
          color: #333;
        }
      }
    }

    // Desktop filter adjustments
    @media (min-width: 783px) {
      gap: 0.4rem;

      .ambi-filter-group {
        flex: 0;
        min-width: auto;
      }

      .ambi-filter-label {
        font-size: 0.7rem;
      }

      .ambi-filter-buttons {
        gap: 0.25rem;
      }

      .ambi-filter-button {
        min-height: 44px;
        padding: 0 0.8rem;
        font-size: 0.8rem;
        gap: 0.25rem;

        .dashicons {
          font-size: 16px;
          width: 16px;
          height: 16px;
        }
      }
    }
  }

  // Pagination styling - mobile first
  .tablenav-pages {
    .displaying-num {
      font-size: 0.75rem;
      color: #666;
      margin-right: 0.5rem;
      white-space: nowrap;
      position: static;
      padding: 0;
    }

    .pagination-links {
      display: flex;
      align-items: center;
      gap: 0.25rem;
      flex-wrap: nowrap;

      .button {
        padding: 0.1rem 0.3rem;
        font-size: 0.7rem;
        border-radius: 3px;
        text-decoration: none;
        border: 1px solid #ddd;
        background: #f1f1f1;
        color: #666;
        min-width: 1.25rem;
        text-align: center;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        line-height: 1;

        &:not(.disabled):hover {
          background: #e6e6e6;
          border-color: #999;
          color: #333;
        }

        &.disabled {
          opacity: 0.5;
          cursor: not-allowed;
        }
      }

      .paging-input {
        display: flex;
        align-items: center;
        margin: 0 0.25rem;
        white-space: nowrap;

        .current-page {
          width: 2.5rem;
          padding: 0.125rem 0.25rem;
          text-align: center;
          border: 1px solid #ddd;
          border-radius: 3px;
          margin: 0 0.25rem;
        }

        .tablenav-paging-text {
          font-size: 0.75rem;
          color: #666;
        }
      }
    }
  }

  // Tablet and up - same sizing, just layout adjustments
  @media (min-width: 783px) {
    .tablenav.top {
      .actions {
        margin-bottom: 0;
        min-width: 0;
      }

      .bulkactions {
        margin-bottom: 0;
        min-width: 0;
      }
    }
  }

  // Large screens - same sizing, only layout changes
  @media (min-width: 1280px) {
    .tablenav.top {
      flex-wrap: nowrap;
      gap: 0.8rem;
      align-items: center;

      .actions {
        flex: 1;
        margin-bottom: 0;
        min-width: 0;
        max-width: none;
        order: 1;
      }

      .tablenav-pages {
        flex: 0 0 auto;
        margin-left: 0.8rem;
        order: 2;
        min-width: auto;
      }
    }
  }

  & > .notice {
    margin: 0;

    &:last-of-type {
      margin-bottom: 1rem;
    }
  }

  & > form > .ambi-box {
    margin-bottom: 2rem;
  }
}

.ambi-header {
  display: flex;
  gap: 1rem;
  align-items: center;

  &__logo {
    margin: 0;
    color: variables.$color-primary;
    font-weight: bold;
    white-space: nowrap;
  }

  &__separator {
    opacity: .5;
    margin: 0 0.5rem;
  }

  &__title {
    font-weight: bold;
    color: #fff;
  }
}

.ambi-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;

  &__link {
    color: #fff;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.9rem;

    &:hover, &:focus {
      color: #fff;
      background: rgba(255, 255, 255, 0.1);
    }

    &--current,
    &.current {
      background: rgba(255, 255, 255, 0.2);
      color: #fff;
      font-weight: 500;

      &:hover {
        background: rgba(255, 255, 255, 0.25);
      }
    }
  }
}

.ambi-breadcrumbs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #ddd;
    font-size: 0.8rem;
    color: #000;
    flex-wrap: wrap;

    // Desktop breadcrumbs adjustments
    @media (min-width: 783px) {
        margin-bottom: 1.5rem;
        padding-bottom: 0;
        font-size: 0.875rem;
        flex-wrap: nowrap;
    }

    &__separator {
        opacity: 0.5;
    }

    &__current {
        font-weight: 700;
    }
}

.ambi-notice {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 1rem;
  margin-bottom: 1.5rem;
  border: 1px solid variables.$color-primary;
  background: rgba(variables.$color-primary, .5);

  &:before {
    content: 'i';
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 100%;
    border: 1px solid variables.$color-primary--dark;
    color: variables.$color-primary--dark;
  }
}

.ambi-grid {
  align-items: stretch;
  flex-direction: column;

  &,
  &__column {
    display: flex;
    gap: 1.5rem;
  }

  &__column {
    flex: 1 1 100%;
    flex-direction: column;
    max-width: 100%;
  }

  @media (min-width: 783px) {
    flex-direction: row;

    &__column {
      max-width: calc(50% - .75rem);
    }
  }
}

.ambi-box {
  display: block;
  height: 100%;
  background-color: #fff;
  transition: box-shadow .2s;

  &,
  &:hover {
    color: initial;
    text-decoration: none;
  }

  &__title,
  &__description {
    padding: 0 1.5rem;
    margin: 0;
  }

  &__title {
    padding-top: 1.5rem;
  }

  &__description {
    padding-top: .5rem;
    padding-bottom: 1.5rem;
  }

  &__button {
    display: block;
    opacity: .5;
    transition: color .2s;
  }

  &__thumbnail {
    max-width: 100%;
    margin-bottom: 1.5rem;

    & + .ambi-box__title {
      padding-top: 0;
    }
  }

  &:hover {
    box-shadow: 0 0 1rem rgba(0,0,0, .1);

    .ambi-box__button {
      color: variables.$color-primary;
    }
  }
}

.activity-logs_page_ambiscale-activity-manager-debug-logs {
  .column-time {
    width: 12.5rem;
  }

  .column-event_type {
    width: 6rem;
  }
}

.ambi-progress-bar {
  &__bar,
  &__progress {
    width: 100%;
    height: .5rem;
    background-color: #eee;
  }

  &__bar {
    margin: .25rem 0;
  }

  &__progress {
    max-width: 100%;
    background-color: variables.$color-primary;
  }

  &__title {
    font-weight: bold;
  }

  &__description {
    font-size: 75%;
  }
}

.ambi-ajax-message {
  display: block;
  margin-top: .25rem;
  color: variables.$color-primary;

  &--error {
    color: variables.$color-red;
  }
}

.ambi-status-icon {
  display: flex;
  align-items: center;
  gap: .5rem;

  &:before {
    content: '';
    width: .75rem;
    height: .75rem;
    border-radius: 100%;
    background: #ccc;
  }

  &--on:before {
    background: variables.$color-primary;
  }
}

.ambi-table-accordion {
  cursor: pointer;

  &__title {
    opacity: .5;
    &:hover {
      opacity: 1;
    }
  }

  &__description {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: .2s all;

    &--open {
      margin-top: .25rem;
      padding-top: .25rem;
      border-bottom: 1px solid rgba(0,0,0, .25);
      max-height: 100%;
      opacity: 1;
    }

    .ambi-table-accordion__description--open {
      max-height: 30rem;
    }
  }
}

.ambi-credits {
  &__container {
    padding: 1rem 2rem;
    background: variables.$color-black;
    color: #fff;
  }
}

.ambi-color-primary {
  color: variables.$color-primary;
}

.ambi-logs-header {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    flex-direction: column;
    align-items: stretch;

    &__content {
        flex: 1;
    }

    &__title {
        margin: 0 0 0.375rem 0;
        font-size: 1.1rem;
        font-weight: 600;
        color: #333;
    }

    &__description {
        margin: 0;
        color: #666;
        line-height: 1.4;
        font-size: 0.875rem;
    }

    &__actions {
        flex-shrink: 0;
        display: flex;
        align-items: flex-start;
        align-self: flex-end;
    }

    // Desktop logs header adjustments
    @media (min-width: 783px) {
        padding: 1.5rem;
        margin-bottom: 1.5rem;
        flex-direction: row;
        align-items: flex-start;
        gap: 1rem;

        &__title {
            margin-bottom: 0.5rem;
            font-size: 1.25rem;
        }

        &__description {
            font-size: 1rem;
            line-height: 1.5;
        }

        &__actions {
            align-self: flex-start;
        }
    }
}

.ambi-logs-refresh-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    white-space: nowrap;
    line-height: 1.2;
    vertical-align: middle;

    .dashicons {
        font-size: 16px;
        width: 16px;
        height: 16px;
        line-height: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        vertical-align: middle;
        margin: 0;
        position: relative;
        top: -1px; // Adjust for dashicon baseline
    }

    &:hover .dashicons {
        animation: spin 1s linear infinite;
    }
}

.ambi-notice-warning {
  color: #d63638;
  font-style: italic;
  margin-top: 0.5rem;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
