// Copyright (C) 2025 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

@import "common";
@import "./graph/graph.scss";
@import "./graph/text_label.scss";
@import "./help.scss";
@import "./graph/node_box.scss";
@import "./node_styling_widgets.scss";
@import "./node_explorer.scss";
@import "./operations/operation_component.scss";
@import "./nodes/sources/slices_source.scss";
@import "./nodes/sources/table_source.scss";
@import "./nodes/sources/timerange_source.scss";
@import "./nodes/add_columns_node.scss";
@import "./nodes/aggregation_node.scss";
@import "./nodes/modify_columns_node.scss";
@import "./table_list.scss";
@import "./function_list.scss";
@import "./widgets.scss";
@import "./join_widgets.scss";

.pf-query-builder-layout {
  // CSS variable for side panel width, used in both SCSS and TypeScript
  --pf-qb-side-panel-width: 60px;

  height: 100%;

  // DrawerPanel's main section needs to have the grid layout
  .pf-drawer-panel__main {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    overflow: hidden;
  }

  .pf-qb-node-graph {
    grid-column: 1;
    overflow: auto;
    position: relative;
  }

  // Position the resize handle in the grid, but let the widget handle its own styling
  .pf-resize-handle {
    grid-column: 2;
  }

  .pf-qb-explorer {
    grid-column: 3;
    overflow: hidden;
    height: 100%;
    // Width is controlled by inline style for smooth resizing
  }

  .pf-qb-side-panel {
    grid-column: 4;
    width: var(--pf-qb-side-panel-width);
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 0;
    border-left: 1px solid var(--pf-color-border);
    padding: 0;
    align-items: stretch;
    justify-content: flex-start;

    .pf-button {
      width: 100%;
      height: 60px;
      font-size: var(--pf-font-size-xxl);
      box-shadow: none;
      border: none;
      border-radius: 0;
      border-bottom: 1px solid var(--pf-color-border);

      &.pf-active {
        background-color: var(--pf-color-primary);
        color: var(--pf-color-text-on-primary);
      }
    }
  }

  .pf-qb-floating-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;

    .pf-button {
      width: 60px;
      height: 60px;
      font-size: 28px;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);

      &:hover {
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
        transform: scale(1.05);
      }
    }
  }

  .pf-qb-floating-controls-bottom {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  // Shared styling for all round action buttons (undo/redo/add node)
  .pf-qb-round-action-button {
    width: 40px;
    height: 40px;
    font-size: var(--pf-font-size-xxl);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: box-shadow 0.2s ease;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }
  }

  .pf-qb-floating-warning {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: var(--pf-color-danger);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
    cursor: pointer;

    &:hover {
      box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
      transform: scale(1.05);
    }

    .pf-qb-warning-icon {
      color: white;
      font-size: 28px;
    }
  }

  &.explorer-collapsed {
    .pf-resize-handle {
      display: none;
    }

    .pf-qb-explorer {
      border-left: none;
      overflow: hidden;
    }
  }
}

.pf-unselected-explorer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  height: 100%;
  padding: 24px;
  overflow-y: auto;

  // Center content when small, scroll when large
  &::before {
    content: "";
    flex-grow: 1;
  }

  &::after {
    content: "";
    flex-grow: 1;
  }
}

.pf-source-cards-horizontal {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding-bottom: 8px;
  max-width: 380px;
}

.pf-template-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
  max-width: 510px;
}

.pf-top-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
  max-width: 750px;
}

.pf-tutorial-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
  max-width: 500px;
}

.pf-solution-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 24px;
  max-width: 510px;
}

.pf-recent-graphs-section {
  margin-bottom: 24px;
  width: 100%;
  max-width: 510px;
  text-align: center;
}

.pf-recent-graphs-scroll-container {
  max-height: 280px;
  overflow-y: auto;
}

.pf-recent-graphs-empty {
  color: var(--pf-color-text-muted);
  font-size: var(--pf-font-size-m);
  font-style: italic;
}

.pf-recent-graph-card {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;

  > div:not(.pf-recent-graph-card__actions) {
    flex: 1;
    min-width: 0;
  }

  h3 {
    margin: 0;
    font-size: var(--pf-font-size-m);
    font-weight: 500;
  }

  p {
    margin: 0;
    font-size: var(--pf-font-size-s);
    color: var(--pf-color-text-muted);
  }

  .pf-recent-graph-card__actions {
    display: flex;
    visibility: hidden;
    flex-shrink: 0;
  }

  &:hover .pf-recent-graph-card__actions,
  &:focus-within .pf-recent-graph-card__actions {
    visibility: visible;
  }
}

.pf-starting-section-title {
  font-size: 16px;
  font-weight: 500;
  margin-top: 24px;
  margin-bottom: 12px;
  color: var(--pf-color-text-primary);

  &:first-child {
    margin-top: 0;
  }
}

.pf-template-card {
  display: flex;
  flex-direction: column;
  gap: 8px;

  .pf-source-card-clickable {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    transition: transform 0.1s ease;

    .pf-icon {
      font-size: 32px;
      color: var(--pf-color-primary);
      transition: color 0.1s ease;
    }

    h3 {
      margin: 0;
      font-size: var(--pf-font-size-l);
      font-weight: 500;
      transition: color 0.1s ease;
    }
  }

  &:hover .pf-source-card-clickable,
  &:focus-within .pf-source-card-clickable {
    transform: translateY(-2px);

    .pf-icon {
      color: var(--pf-color-accent);
    }

    h3 {
      color: var(--pf-color-accent);
    }
  }

  p {
    margin: 0;
    font-size: var(--pf-font-size-m);
    line-height: 1.4;
    color: var(--pf-color-text-muted);
    text-align: center;
  }
}

.pf-source-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;

  .pf-source-card-clickable {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-bottom: 2px;
    transition: transform 0.1s ease;

    .pf-icon {
      font-size: var(--pf-font-size-xxl);
      color: var(--pf-color-primary);
      transition: color 0.1s ease;
    }

    h3 {
      margin: 0;
      font-size: var(--pf-font-size-m);
      font-weight: 500;
      transition: color 0.1s ease;
      text-align: center;
    }
  }

  &:hover .pf-source-card-clickable,
  &:focus-within .pf-source-card-clickable {
    transform: translateY(-2px);

    .pf-icon {
      color: var(--pf-color-accent);
    }

    h3 {
      color: var(--pf-color-accent);
    }
  }

  p {
    margin: 0;
    font-size: var(--pf-font-size-s);
    line-height: 1.3;
    color: var(--pf-color-text-muted);
    text-align: center;
  }

  .pf-source-card-hotkey {
    align-self: center;
    margin-top: 2px;
  }
}

.pf-examples-modal {
  padding: 16px;
}

.pf-examples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  max-width: 800px;
}

.pf-example-card {
  display: flex;
  flex-direction: column;
  gap: 8px;

  .pf-example-card-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    transition: transform 0.1s ease;

    .pf-icon {
      font-size: 32px;
      color: var(--pf-color-primary);
      transition: color 0.1s ease;
    }

    h3 {
      margin: 0;
      font-size: var(--pf-font-size-l);
      font-weight: 500;
      transition: color 0.1s ease;
    }
  }

  &:hover .pf-example-card-content,
  &:focus-within .pf-example-card-content {
    transform: translateY(-2px);

    .pf-icon {
      color: var(--pf-color-accent);
    }

    h3 {
      color: var(--pf-color-accent);
    }
  }

  p {
    margin: 0;
    font-size: var(--pf-font-size-s);
    line-height: 1.4;
    color: var(--pf-color-text-muted);
    text-align: center;
  }
}

.pf-error-details {
  min-width: 300px;
  max-width: 500px;
  max-height: 400px;
  overflow-y: auto;
  padding: 12px;
  font-size: var(--pf-font-size-s);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--pf-font-family-monospace, "Roboto Mono", monospace);
}
