
@import "../../variables/_dlt-c8y-icons-vars.less";
@import "../mixins/_c8y-scrollbar.less";
@import "../mixins/_icon-base.less";

/**
 * Dashboard Styles - Grid-based dashboard layout with drag-and-drop
 *
 * Note: Uses design tokens for spacing (@size-*; @component-padding) and colors.
 *
 * Intentionally hardcoded values:
 * - Media query breakpoint (768px): Responsive breakpoint
 * - Border widths (1px, 2px): Standard border sizes
 * - Widget dimensions (30px, 40px, 65px, 99vh): Component-specific sizes
 * - Min-heights (6px): Off-grid positioning
 * - Transition duration (0.3s): Animation timing
 * - Opacity values: Visual effects
 * - Z-index values (1085, 100, 12, 11, 10, 9): Stacking order
 * - Percentages and viewport units: Layout calculations
 * - Line-height (0.5): Typography ratio
 * - Padding 3px (off-grid): Fine-tuning for template marker
 * - Height 14px (off-grid): Template marker height
 */

@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr !important;
  }

  .dashboard-grid-child {
    grid-column-start: 1 !important;
    grid-column-end: 1 !important;
    grid-row-start: auto !important;
  }
  .card-header-grid.cdk-drag-handle {
    cursor: auto;
  }
}

body.c8y-grid-dashboard > .card.card-dashboard.cdk-drag-preview {
  opacity: 0.8;
}

.dashboard-grid {
  display: grid;

  .dashboard-grid-child {
    min-width: 0;
  }

  .cdk-drop-list {
    position: relative;
  }

  .card-dashboard {
    overflow: hidden;
  }

  .card-dashboard.on-resize {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0.8;
  }

  .card-dashboard.panel-content-transparent.on-resize {
    outline: 1px solid @component-brand-primary;
  }

  .card-header-grid {
    min-height: 6px;
    height: auto !important;
  }

  .card-header-actions:after,
  .card-header-actions + .card-inner-scroll:before {
    display: none;
  }

  .header-actions {
    top: 0;
    right: 0;
    z-index: 10;
  }

  .resize-handle {
    position: absolute;
    right: 0;
    bottom: 0;
    z-index: 12;
    width: 30px;
    height: 30px;
    cursor: se-resize;
  }

  .resize-icon {
    position: absolute;
    .dlt-c8y-icon();
    right: @size-4;
    bottom: @size-4;
    z-index: 11;
    width: @size-20;
    height: @size-20;
    opacity: 0;
    cursor: se-resize;
    transition: opacity 0.3s ease-in-out;
    transform: rotate(-90deg);

    &:before {
      content: @dlt-c8y-icon-enlarge;
    }
  }

  .card-dashboard:hover .resize-icon {
    opacity: 0.25;
  }

  .resize-handle:hover + .resize-icon {
    opacity: 1;
  }

  .on-resize .resize-icon {
    opacity: 1 !important;
  }

  .card-placeholder {
    height: 100%;
    opacity: 1 !important;
    outline: 2px dotted @component-border-color !important;
    outline-offset: 0;
  }

  .cdk-drop-list,
  .card-dashboard {
    height: 100%;
  }
}

.fullscreen-dashboard-styles {
  overflow: hidden;
  .navigator,
  .app-main-header {
    display: none;
  }

  .mcontainer {
    margin-top: 0;
    margin-left: 0 !important;
    padding: 0 !important;
    background-color: @body-background-color;

    > .container-fluid {
      padding-bottom: 0;
    }
  }

  .c8y-ui-action-bar {
    top: 0 !important;
    left: 0 !important;
  }



  .dashboard {
    top: 0;
    left: 0;
    z-index: 1085 !important;
    overflow-y: auto;
    margin: 0 !important;
    padding-top: calc(@size-base * 10);
    padding-bottom: @size-24 !important;
    width: 100vw;
    height: 99vh;
    .c8y-scrollbar();

    .dashboard {
      padding-bottom: 0 !important;

      all: unset;
    }

    .dashboard-container {
      margin-top: 0 !important;
      margin-bottom: 0 !important;
    }
  }

  .page-tabs:not(.c8y-top-drawer--tabs) {
    display: none;
  }
}

.fullscreen-dashboard {
  .fullscreen-dashboard-styles();
}

// hide action bar when a single widget is in fullscreen
.singleWidget {
  .c8y-ui-action-bar {
    display: none !important;
  }
  .dashboard-grid-child:not(.fullscreen) {
    display: none !important;
  }
  .dashboard-grid-child.fullscreen {
    position: fixed;
    inset: @size-24;
    z-index: 100;
    margin: 0 !important;
  }
  .dashboard {
    overflow: hidden !important;
  }
}

:-webkit-full-screen:not(:root) {
  .fullscreen-dashboard-styles();
}

:-moz-full-screen:not(:root) {
  .fullscreen-dashboard-styles();
}

:-ms-fullscreen:not(:root) {
  .fullscreen-dashboard-styles();
}

:fullscreen:not(:root) {
  .fullscreen-dashboard-styles();
}

body .dashboard-preview-slot {
  margin: 0 !important;
  padding: 30px;
  border: 1px solid @component-border-color;
  .page-tabs-horizontal {
    margin-top: 2px !important;
  }

  .card.card-dashboard {
    position: relative;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    margin: 0 !important;
  }
}
body fieldset > .dashboard-preview-slot {
  border: 0;
  padding: 0;
  margin: 0 !important;
}

// title hidden
.card.card-dashboard {
  .panel-title-hidden &,
  .dashboard-preview-slot.panel-title-hidden,
  &.panel-title-hidden.cdk-drag-disabled {
    .card-header-actions {
      position: absolute;
      z-index: 10;
      min-height: 6px;
      width: 100%;
      height: 0;
      border: 0;
      pointer-events: none;
      &:after {
        display: none;
      }

      > * {
        display: none;
      }

      > .header-actions {
        position: absolute;
        top: 0;
        right: 0;
        z-index: 10;
        display: flex;
        border-left: 0;
        opacity: 0;
      }

      + .card-inner-scroll {
        top: 0;
        z-index: 9;
        height: 100%;

        // Removed unused state modifier class - verified 0 usages: .has-footer

        &:before {
          display: none;
        }

        .leaflet-top .leaflet-control {
          margin-top: @size-16;
        }
        .c8y-map-status {
          margin-top: 0;
        }
        .sticky-top {
          padding-top: @size-base;
        }
      }
    }
  }
}

// title overlay
.card.card-dashboard {
  .panel-title-overlay &,
  .dashboard-preview-slot.panel-title-overlay &,
  &.panel-title-overlay.cdk-drag-disabled {
    .card-header-actions {
      position: absolute;
      z-index: 10;
      width: 100%;
      border: 0;
      pointer-events: none;

      &:after {
        display: none;
      }

      .card-header-title {
        min-height: 40px;
      }

      > .header-actions {
        position: absolute;
        top: 0;
        right: 0;
        z-index: 10;
        display: flex;
        border-left: 0;
        opacity: 0;
      }

      + .card-inner-scroll {
        top: 0;
        z-index: 9;
        height: 100%;
        &:before {
          display: none;
        }
        .leaflet-top .leaflet-control {
          margin-top: 40px;
        }
        .c8y-map-status {
          margin-top: @size-24;
        }
        .sticky-top {
          padding-top: @size-base;
        }
      }
    }
  }
}

//title border
.card.card-dashboard {
  .panel-title-border &,
  .dashboard-preview-slot.panel-title-border &,
  &.panel-title-border {
    .card-header-actions {
      z-index: 10;
      border-color: @component-border-color;
      border-top: 1px solid transparent;
      border-bottom-width: 1px;
      border-bottom-style: solid;

      &:after {
        display: none;
      }

      + .card-inner-scroll {
        &:before {
          display: none;
        }
      }
    }
  }
}

.dashboard-template-marker {
  color: var(--palette-status-info, var(--c8y-palette-status-info));
  line-height: 0.5;
  font-size: @size-10;
  font-weight: bold;
  padding: @size-4 3px;
  border: 1px solid;
  height: 14px;
  display: inline-block;
  &::before {
    content: 'T';
  }
  .label &,
  .tag & {
    position: static;
    margin: 0 @size-4 0 calc(-1 * @size-4);
  }
  .tag--info & {
    color: inherit;
  }
}
// Prevent interactions in dashboard preview slots except for maps
.dashboard-preview-slot:not(:has(c8y-map)){
  pointer-events: none;
  cursor: forbidden;
}

// data-grid--custom-column-header- styles
.dashboard-preview-slot,
.card-dashboard{
  .table-data-grid-header > .h4{
    display: none;
  }
  .content-fullpage{
    height: 100%!important;
  }
  c8y-asset-table-widget-view.hide-footer {
    .table-data-grid-footer {
      display: none;
    }
  }
}
