@use '../mixins/_media-queries';

:root {
  //--mat-fab-small-container-elevation-shadow: var(--whiteframe-shadow-4dp);
  --mat-dialog-container-small-max-width: 94vw;
  --mat-dialog-container-max-width: 85vw;
  --mat-menu-item-label-text-size: 14px;

  // Tab contrast improvements - use darker shade for light theme
  --mat-tab-header-active-label-text-color: var(--palette-primary-700);
  --mat-tab-header-active-ripple-color: var(--palette-primary-700);
  --mat-tab-header-active-focus-label-text-color: var(--palette-primary-700);
  --mat-tab-header-active-hover-label-text-color: var(--palette-primary-700);
  --mdc-tab-indicator-active-indicator-color: var(--palette-primary-700);
  --mat-tab-header-inactive-label-text-color: var(--text-color-muted);
}

// Dark theme tab overrides for better contrast - use lighter shade
body.isDarkTheme {
  --mat-tab-header-active-label-text-color: var(--palette-primary-300);
  --mat-tab-header-active-ripple-color: var(--palette-primary-300);
  --mat-tab-header-active-focus-label-text-color: var(--palette-primary-300);
  --mat-tab-header-active-hover-label-text-color: var(--palette-primary-300);
  --mdc-tab-indicator-active-indicator-color: var(--palette-primary-300);
}

// Apply tab colors explicitly to tab components
.mat-mdc-tab-group,
.mat-mdc-tab-nav-bar {
  // Active tab label color
  .mdc-tab--active .mdc-tab__text-label {
    color: var(--mat-tab-header-active-label-text-color);
  }

  // Active tab indicator (underline)
  .mdc-tab-indicator--active .mdc-tab-indicator__content--underline {
    border-color: var(--mdc-tab-indicator-active-indicator-color);
  }

  // Inactive tab labels
  .mdc-tab:not(.mdc-tab--active) .mdc-tab__text-label {
    color: var(--mat-tab-header-inactive-label-text-color);
  }
}

* {
  --mat-chip-container-shape-radius: 4px !important;
  --mat-chip-elevated-container-color: transparent !important;
  //--mat-chip-outline-color: var(--mat-chip-outline-color, var(--mat-sys-outline)) !important;
  --mat-chip-outline-color: var(--chip-outline-color) !important;
  --mat-chip-outline-width: 1px !important;
}

.mat-drawer.mat-drawer-side {
  // should be below notes panel
  z-index: 1 !important;
}

// on android this is not properly injected for unknown reasons
.cdk-overlay-container {
  z-index: 1000;
}

// DIALOGS
// ----------
.mat-mdc-dialog-title.mat-mdc-dialog-title,
.mdc-dialog__title.mdc-dialog__title {
  margin-bottom: 0;
  margin-top: 8px;
  display: flex;
  align-items: center;
}

.cdk-overlay-pane.mat-mdc-dialog-panel {
  @include media-queries.mq(xs, max) {
    max-width: 96vw !important;
  }
}

body .mat-mdc-dialog-content {
  overflow: auto;

  mat-form-field {
    display: block;
  }
}

body .mat-mdc-dialog-surface {
  overflow: visible;
}

.mat-mdc-dialog-panel {
  @include media-queries.mq(xs) {
    //--mat-dialog-container-min-width: 350px;
  }
}

.mat-mdc-dialog-title {
  vertical-align: middle;

  > * {
    vertical-align: middle;
  }

  > mat-icon:first-child {
    margin-right: 8px;
  }
}

.big {
  height: auto;
  max-height: 100vh !important;
  // mobile viewport bug fix
  max-height: -webkit-fill-available;
  width: 100% !important;
  max-width: none !important;

  @include media-queries.mq(xs) {
    margin: var(--s2);
    max-height: 95vh !important;
  }
}

// FORMS
// --------
.mat-mdc-form-field {
  margin-bottom: var(--s2);
}

// needs to be global cause of cdk overlay
// is used for select-task
mat-option.isDone {
  .mdc-list-item__primary-text {
    text-decoration: line-through !important;
    opacity: 0.4 !important;
  }
}

// BUTTONS
// -----------
// Ensure proper contrast for text and stroked buttons on standard backgrounds
// Text buttons use theme colors directly on background, so we need good contrast
.mat-mdc-button,
.mat-mdc-outlined-button {
  &[color='primary'] {
    // Use primary color - validated palettes ensure WCAG AA compliance
    --mdc-text-button-label-text-color: var(--palette-primary-500);
    --mdc-outlined-button-label-text-color: var(--palette-primary-500);
    --mdc-outlined-button-outline-color: var(--palette-primary-500);
  }

  &[color='accent'] {
    // Use accent color - validated palettes ensure WCAG AA compliance
    --mdc-text-button-label-text-color: var(--palette-accent-500);
    --mdc-outlined-button-label-text-color: var(--palette-accent-500);
    --mdc-outlined-button-outline-color: var(--palette-accent-500);
  }

  &[color='warn'] {
    // Use warn color - validated palettes ensure WCAG AA compliance
    --mdc-text-button-label-text-color: var(--palette-warn-500);
    --mdc-outlined-button-label-text-color: var(--palette-warn-500);
    --mdc-outlined-button-outline-color: var(--palette-warn-500);
  }
}

.mat-mdc-menu-item-text {
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  max-width: 100%;
  white-space: nowrap;

  display: flex;
  justify-content: space-between;
  align-items: center;

  plugin-icon {
    margin-right: 14px;
  }

  span {
    margin-right: auto;
  }
}

.mat-mdc-icon-button.mat-mdc-button-base {
  --mat-icon-button-state-layer-size: 40px;
}

.mat-mdc-mini-fab.mat-mdc-mini-fab.mat-mdc-mini-fab {
  --mat-fab-small-state-layer-size: 48px;
}

.mat-mdc-icon-button.mat-mdc-icon-button.mat-mdc-icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;

  .mat-mdc-button-touch-target {
    width: 40px;
    height: 40px;
  }
}

// ICONS
// -----

mat-icon,
.mat-icon {
  vertical-align: middle;
}

.mat-icon.mat-icon {
  // to make utf emojis look better
  overflow: visible;
}

.mat-icon {
  // for some reason material puts that to transform and it is bad for performance
  will-change: auto !important;
}

mat-icon.mat-icon[svgicon] {
  display: flex;
  justify-content: center;
}

// Ensure icon flex behaviour stays consistent even before Angular Material
// injects the MatButton styles (which set min-height: fit-content lazily).
body .mat-mdc-button-base .mat-icon {
  //flex-shrink: 1 !important;
  min-height: auto !important;
}

// AUTOCOMPLETE
// -----------------
.mdc-list-item__primary-text {
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

// CDK DRAG
/* Animate items as they're being sorted. */
.cdk-drop-list-dragging .cdk-drag {
  transition: transform 100ms cubic-bezier(0, 0, 0.2, 1);
}

/* Animate an item that has been dropped. */
.cdk-drag-animating {
  transition: transform 100ms cubic-bezier(0, 0, 0.2, 1);
}

.cdk-drag-preview {
  box-shadow: var(--whiteframe-shadow-8dp) !important;
  cursor: grabbing !important;
  overflow: hidden;
  pointer-events: none !important;

  &:hover,
  &:active {
    cursor: grabbing !important;
  }

  background: var(--bg-lightest) !important;
}

.drag-preview-time-badge {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  font-weight: bold;
  border: 2px solid var(--c-primary);
  border-radius: var(--card-border-radius);
  background: var(--bg-lighter);
  background: inherit;
  z-index: 100;
  pointer-events: none;
  padding: 2px 6px;
  box-shadow: var(--whiteframe-shadow-3dp);
  white-space: nowrap;
}

.cdk-drag-placeholder {
  cursor: grabbing;
  opacity: 0.1;
}

.cdk-drop-list-dragging {
  outline: 1px dashed var(--c-primary);
  border-radius: 6px;
  cursor: grabbing;
}

.cdk-drop-list-disabled {
  border: 4px solid red;
}

.cdk-drop-list-receiving {
  outline: 1px dashed var(--c-primary);
  border-color: var(--c-primary);
  border-radius: 6px;
  cursor: grabbing;
  //border: 2px solid green;
}

// MAT MENU
.mat-mdc-menu-content {
  padding: 0 !important;
}

.mat-mdc-menu-item.quick-access {
  border: 1px solid red;
}

task.cdk-drag-preview .box {
  background: var(--bg-lightest) !important;
}

// MAT TOOLTIP
mat-tooltip-component {
  pointer-events: none;
}

// SNACK
// Move snack bar above mobile bottom nav for all touch devices
@include media-queries.mq(xs, max) {
  // Apply to all touch devices, not just when mobile bottom nav is shown
  body.hasMobileBottomNav .mat-mdc-snack-bar-handset {
    pointer-events: none;
  }
  body.hasMobileBottomNav mat-snack-bar-container {
    margin-bottom: calc(
      var(--bottom-nav-height) + env(safe-area-inset-bottom) + 24px
    ) !important;
    pointer-events: auto;
    transition: 150ms margin;
  }
  body.hasMobileBottomNav.isAddTaskBarOpen mat-snack-bar-container {
    margin-bottom: calc(
      var(--bottom-nav-height) + env(safe-area-inset-bottom) + 48px
    ) !important;
    pointer-events: auto;
  }
}
