.timeline-container {
  width: 100%;
  overflow: visible;
}

.timeline-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: flex-start;
  margin-bottom: 0.5rem;
  gap: 1rem;

  .header-title {
    h3 {
      color: var(--text-color, #ffffff);
      font-size: 1.25rem;
      font-weight: 500;
      margin: 0 0 0.5rem 0;
    }

    .timeline-subtitle {
      color: var(--text-secondary-color);
      font-size: 0.9rem;
      margin: 0;
      line-height: 1.4;
    }
  }

  .week-info {
    display: flex;
    align-items: center;
    justify-self: center;

    .week-nav-btn {
      background: rgba(255, 255, 255, 0.1);
      border: 1px solid rgba(255, 255, 255, 0.2);
      border-radius: 6px;
      padding: 0.6rem 0.6rem;
      color: #ffffff;
      cursor: pointer;
      transition: all 0.3s ease;
      display: flex;
      align-items: center;
      justify-content: center;

      &:hover {
        background: rgba(255, 255, 255, 0.2);
        border-color: rgba(255, 255, 255, 0.3);
        transform: translateY(-1px);
      }

      &:active {
        transform: translateY(0);
      }

      i {
        font-size: 0.875rem;
      }
    }

    .week-display {
      display: flex;
      flex-direction: column;
      align-items: center;
      min-width: 120px;

      .week-label {
        font-size: 1rem;
        font-weight: 600;
        color: #ffffff;
        white-space: nowrap;
        line-height: 1.2;
      }

      .week-dates {
        font-size: 0.75rem;
        color: var(--text-secondary-color);
        white-space: nowrap;
        margin-top: 0.1rem;
        line-height: 1.2;
      }
    }
  }

  .filter-controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    justify-self: end;
  }
}

.week-info-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);

  .week-nav-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    padding: 0.6rem 6rem;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;

    &:hover {
      background: rgba(255, 255, 255, 0.2);
      border-color: rgba(255, 255, 255, 0.3);
      transform: translateY(-1px);
    }

    &:active {
      transform: translateY(0);
    }

    i {
      font-size: 0.875rem;
    }
  }

  .week-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 150px;

    .week-label {
      font-size: 1.125rem;
      font-weight: 600;
      color: #ffffff;
      white-space: nowrap;
    }

    .week-dates {
      font-size: 0.85rem;
      color: var(--text-secondary-color);
      white-space: nowrap;
      margin-top: 0.25rem;
    }
  }
}

.timeline-content {
  position: relative;
  width: 100%;
  padding: 1rem;
  overflow: visible;
}

.hour-markers {
  display: flex;
  margin-bottom: 0.5rem;

  .day-label-spacer {
    width: 100px;
    flex-shrink: 0;
  }

  .hour-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(24, 1fr);
    position: relative;
  }

  .hour-marker {
    position: relative;
    height: 20px;

    &.major {
      .hour-label {
        display: block;
      }
    }
  }

  .hour-label {
    display: none;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    position: absolute;
    left: 0;
    transform: translateX(-50%);
    white-space: nowrap;
  }
}

.timeline-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: visible;
}

.timeline-row {
  display: flex;
  align-items: stretch;
  overflow: visible;

  .day-label {
    width: 50px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    font-size: 0.875rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    padding-right: 1rem;
  }

  .timeline-track {
    flex: 1;
    position: relative;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    min-height: 35px;
    overflow: visible;
  }
}

.grid-lines {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  pointer-events: none;

  .grid-line {
    border-right: 1px solid rgba(255, 255, 255, 0.05);

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

.sessions {
  position: absolute;
  inset: 4px;
  pointer-events: none;
  overflow: visible;

  .session-block {
    position: absolute;
    border-radius: 4px;
    pointer-events: auto;
    cursor: pointer;
    transition: all 0.2s ease;
    overflow: visible;
    box-sizing: border-box;

    &.book-type-epub, &.book-type-default {
      background: color-mix(in srgb, var(--book-type-epub-color) 80%, transparent);
      border: 1px solid var(--book-type-epub-color);
      box-shadow: 0 2px 4px color-mix(in srgb, var(--book-type-epub-color) 30%, transparent);

      &:hover {
        box-shadow: 0 4px 8px color-mix(in srgb, var(--book-type-epub-color) 50%, transparent);
      }
    }

    &.book-type-pdf {
      background: color-mix(in srgb, var(--book-type-pdf-color) 80%, transparent);
      border: 1px solid var(--book-type-pdf-color);
      box-shadow: 0 2px 4px color-mix(in srgb, var(--book-type-pdf-color) 30%, transparent);

      &:hover {
        box-shadow: 0 4px 8px color-mix(in srgb, var(--book-type-pdf-color) 50%, transparent);
      }
    }

    &.book-type-cbx {
      background: color-mix(in srgb, var(--book-type-cbx-color) 80%, transparent);
      border: 1px solid var(--book-type-cbx-color);
      box-shadow: 0 2px 4px color-mix(in srgb, var(--book-type-cbx-color) 30%, transparent);

      &:hover {
        box-shadow: 0 4px 8px color-mix(in srgb, var(--book-type-cbx-color) 50%, transparent);
      }
    }

    &.book-type-fb2 {
      background: color-mix(in srgb, var(--book-type-fb2-color) 80%, transparent);
      border: 1px solid var(--book-type-fb2-color);
      box-shadow: 0 2px 4px color-mix(in srgb, var(--book-type-fb2-color) 30%, transparent);

      &:hover {
        box-shadow: 0 4px 8px color-mix(in srgb, var(--book-type-fb2-color) 50%, transparent);
      }
    }

    &.book-type-mobi {
      background: color-mix(in srgb, var(--book-type-mobi-color) 80%, transparent);
      border: 1px solid var(--book-type-mobi-color);
      box-shadow: 0 2px 4px color-mix(in srgb, var(--book-type-mobi-color) 30%, transparent);

      &:hover {
        box-shadow: 0 4px 8px color-mix(in srgb, var(--book-type-mobi-color) 50%, transparent);
      }
    }

    &.book-type-azw3 {
      background: color-mix(in srgb, var(--book-type-azw3-color) 80%, transparent);
      border: 1px solid var(--book-type-azw3-color);
      box-shadow: 0 2px 4px color-mix(in srgb, var(--book-type-azw3-color) 30%, transparent);

      &:hover {
        box-shadow: 0 4px 8px color-mix(in srgb, var(--book-type-azw3-color) 50%, transparent);
      }
    }

    &.book-type-audiobook {
      background: color-mix(in srgb, var(--book-type-audiobook-color) 80%, transparent);
      border: 1px solid var(--book-type-audiobook-color);
      box-shadow: 0 2px 4px color-mix(in srgb, var(--book-type-audiobook-color) 30%, transparent);

      &:hover {
        box-shadow: 0 4px 8px color-mix(in srgb, var(--book-type-audiobook-color) 50%, transparent);
      }
    }

    &:hover {
      transform: translateY(-2px);
      z-index: 10;
    }

    .session-content {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      height: 100%;
      padding: 4px 8px;
      color: white;
      font-size: 0.7rem;
      font-weight: 500;
      text-align: center;
      gap: 2px;
      overflow: hidden;

      .session-time {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
        line-height: 1;
      }

      .session-duration {
        font-size: 0.65rem;
        opacity: 0.9;
        white-space: nowrap;
        line-height: 1;
      }
    }
  }
}

::ng-deep .session-timeline-tooltip.p-tooltip {
  --p-tooltip-max-width: 300px;
  --p-tooltip-background: rgba(30, 30, 30, 0.98);
  --p-tooltip-color: #ffffff;
  --p-tooltip-border-radius: 12px;
  --p-tooltip-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  --p-tooltip-padding: 0 !important;
  --p-tooltip-gutter: 12px;

  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  min-width: 320px;
  padding: 0 !important;

  .p-tooltip-text {
    padding: 0 !important;
    margin: 0 !important;
    white-space: normal;
  }

  .session-tooltip-content {
    display: flex;
    gap: 1rem;
    padding: 0.75rem;
  }

  .session-tooltip-cover {
    flex-shrink: 0;
    width: 80px;
    height: 120px;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      border-radius: 4px;
      background-color: rgba(255, 255, 255, 0.1);
    }
  }

  .session-tooltip-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .session-tooltip-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;

    i {
      font-size: 1.1rem;
      color: rgba(239, 68, 68, 1);
    }
  }

  .session-tooltip-title {
    color: #ffffff;
    font-weight: 600;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .session-tooltip-divider {
    height: 1px;
    background: linear-gradient(90deg,
      transparent 0%,
      rgba(255, 255, 255, 0.1) 50%,
      transparent 100%);
    margin-bottom: 0.75rem;
  }

  .session-tooltip-body {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
  }

  .session-tooltip-row {
    display: grid;
    grid-template-columns: auto auto 1fr;
    align-items: center;
    gap: 0.625rem;
    font-size: 0.875rem;

    i {
      font-size: 0.875rem;
      color: rgba(255, 255, 255, 0.6);
      width: 16px;
      text-align: center;
    }
  }

  .session-tooltip-label {
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
  }

  .session-tooltip-value {
    color: #ffffff;
    text-align: right;
    font-weight: 500;
  }
}

.timeline-title-icon {
  font-size: 1.5rem;
  color: rgba(239, 68, 68, 1);
  vertical-align: middle;
  margin-right: 0.25em;
}

@media (max-width: 1024px) {
  .timeline-header {
    grid-template-columns: 1fr;
    gap: 0.75rem;

    .header-title {
      grid-column: 1;
    }

    .week-info {
      grid-column: 1;
      justify-self: stretch;
      justify-content: center;
    }

    .filter-controls {
      grid-column: 1;
      justify-self: stretch;
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 0.5rem;

      ::ng-deep p-select {
        width: 100%;

        .p-select {
          width: 100% !important;
        }
      }
    }
  }
}

@media (max-width: 768px) {
  .timeline-header {
    .header-title {
      h3 {
        font-size: 1.1rem;
      }

      .timeline-subtitle {
        font-size: 0.85rem;
      }
    }

    .week-info {
      padding: 0.6rem 0.6rem;

      .week-display {
        min-width: 100px;

        .week-label {
          font-size: 0.9rem;
        }

        .week-dates {
          font-size: 0.7rem;
        }
      }

      .week-nav-btn {
        padding: 0.35rem 0.5rem;

        i {
          font-size: 0.8rem;
        }
      }
    }
  }

  .timeline-content {
    min-height: 300px;
    padding: 0.75rem;
  }

  .timeline-row {
    .day-label {
      width: 70px;
      font-size: 0.75rem;
      padding-right: 0.5rem;
    }
  }

  .hour-markers {
    .day-label-spacer {
      width: 70px;
    }
  }

  .hour-marker {
    .hour-label {
      font-size: 0.6rem;
    }
  }

  .session-block {
    .session-content {
      font-size: 0.65rem;

      .session-duration {
        display: none;
      }
    }
  }

  .session-tooltip {
    min-width: 240px;
    max-width: 280px;
    font-size: 0.85rem;

    .tooltip-header {
      padding: 0.75rem;

      .tooltip-title {
        font-size: 0.875rem;
      }
    }

    .tooltip-body {
      padding: 0.75rem;
    }

    .tooltip-row {
      font-size: 0.8rem;
      gap: 0.5rem;
    }
  }
}

@media (max-width: 480px) {
  .timeline-header {
    .header-title {
      h3 {
        font-size: 1rem;
      }

      .timeline-subtitle {
        font-size: 0.8rem;
      }
    }

    .filter-controls {
      grid-template-columns: 1fr;
    }

    .week-info {
      .week-display {
        min-width: 90px;

        .week-label {
          font-size: 0.85rem;
        }

        .week-dates {
          font-size: 0.65rem;
        }
      }
    }
  }
}
