@use 'ui-design-system/src/styles/semantic/index' as *;

.demo-container {
  padding: $semantic-spacing-layout-section-md;
  max-width: 1200px;
  margin: 0 auto;
}

.demo-section {
  margin-bottom: $semantic-spacing-layout-section-lg;

  h3 {
    font-family: map-get($semantic-typography-heading-h3, font-family);
    font-size: map-get($semantic-typography-heading-h3, font-size);
    font-weight: map-get($semantic-typography-heading-h3, font-weight);
    line-height: map-get($semantic-typography-heading-h3, line-height);
    color: $semantic-color-text-primary;
    margin-bottom: $semantic-spacing-layout-section-sm;
  }
}

.demo-subsection {
  margin-bottom: $semantic-spacing-layout-section-md;

  h4 {
    font-family: map-get($semantic-typography-heading-h4, font-family);
    font-size: map-get($semantic-typography-heading-h4, font-size);
    font-weight: map-get($semantic-typography-heading-h4, font-weight);
    line-height: map-get($semantic-typography-heading-h4, line-height);
    color: $semantic-color-text-primary;
    margin-bottom: $semantic-spacing-component-md;
  }
}

.demo-row {
  display: flex;
  gap: $semantic-spacing-component-md;
  flex-wrap: wrap;
  align-items: flex-start;

  &--center {
    justify-content: center;
  }
}

.demo-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: $semantic-spacing-component-sm;
}

.demo-trigger-button {
  padding: $semantic-spacing-component-sm $semantic-spacing-component-md;
  background: $semantic-color-primary;
  color: $semantic-color-on-primary;
  border: none;
  border-radius: $semantic-border-button-radius;
  font-family: map-get($semantic-typography-button-medium, font-family);
  font-size: map-get($semantic-typography-button-medium, font-size);
  font-weight: map-get($semantic-typography-button-medium, font-weight);
  line-height: map-get($semantic-typography-button-medium, line-height);
  cursor: pointer;
  transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease;
  min-height: $semantic-sizing-button-height-md;

  &:hover {
    background: $semantic-color-primary;
    opacity: $semantic-opacity-hover;
  }

  &:focus-visible {
    outline: 2px solid $semantic-color-focus;
    outline-offset: 2px;
  }

  &:active {
    transform: translateY(1px);
  }
}

.demo-position-container {
  display: grid;
  grid-template-areas: 
    ". top ."
    "left center right"
    ". bottom .";
  gap: $semantic-spacing-component-lg;
  padding: $semantic-spacing-layout-section-md;
  background: $semantic-color-surface-secondary;
  border-radius: $semantic-border-radius-lg;
  border: $semantic-border-width-1 solid $semantic-color-border-subtle;
}

.demo-position-button {
  padding: $semantic-spacing-component-sm;
  background: $semantic-color-surface-primary;
  color: $semantic-color-text-primary;
  border: $semantic-border-width-1 solid $semantic-color-border-primary;
  border-radius: $semantic-border-radius-md;
  cursor: pointer;
  transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease;
  min-width: 80px;
  text-align: center;
  font-family: map-get($semantic-typography-button-small, font-family);
  font-size: map-get($semantic-typography-button-small, font-size);
  font-weight: map-get($semantic-typography-button-small, font-weight);
  line-height: map-get($semantic-typography-button-small, line-height);

  &--top {
    grid-area: top;
  }

  &--bottom {
    grid-area: bottom;
  }

  &--left {
    grid-area: left;
  }

  &--right {
    grid-area: right;
  }

  &:hover {
    background: $semantic-color-surface-elevated;
    border-color: $semantic-color-border-primary;
    box-shadow: $semantic-shadow-elevation-1;
  }

  &:focus-visible {
    outline: 2px solid $semantic-color-focus;
    outline-offset: 2px;
  }
}

.demo-context-area {
  padding: $semantic-spacing-component-lg;
  background: $semantic-color-surface-primary;
  border: $semantic-border-width-1 solid $semantic-color-border-subtle;
  border-radius: $semantic-border-radius-md;
  margin-bottom: $semantic-spacing-component-md;
  min-height: 120px;
  position: relative;
  cursor: pointer;

  p {
    font-family: map-get($semantic-typography-body-medium, font-family);
    font-size: map-get($semantic-typography-body-medium, font-size);
    font-weight: map-get($semantic-typography-body-medium, font-weight);
    line-height: map-get($semantic-typography-body-medium, line-height);
    color: $semantic-color-text-primary;
    margin: 0 0 $semantic-spacing-content-paragraph 0;

    &:last-child {
      margin-bottom: 0;
    }
  }

  img {
    max-width: 200px;
    height: auto;
    display: block;
    margin: 0 auto $semantic-spacing-component-sm auto;
    border-radius: $semantic-border-radius-sm;
  }

  &:hover {
    background: $semantic-color-surface-elevated;
    border-color: $semantic-color-border-primary;
  }
}

.demo-hint {
  font-family: map-get($semantic-typography-body-small, font-family);
  font-size: map-get($semantic-typography-body-small, font-size);
  font-weight: map-get($semantic-typography-body-small, font-weight);
  line-height: map-get($semantic-typography-body-small, line-height);
  color: $semantic-color-text-secondary;
  text-align: center;
  font-style: italic;
}

.demo-editor {
  min-height: 120px;
  padding: $semantic-spacing-component-md;
  background: $semantic-color-surface-primary;
  border: $semantic-border-width-1 solid $semantic-color-border-primary;
  border-radius: $semantic-border-input-radius;
  font-family: map-get($semantic-typography-body-medium, font-family);
  font-size: map-get($semantic-typography-body-medium, font-size);
  font-weight: map-get($semantic-typography-body-medium, font-weight);
  line-height: map-get($semantic-typography-body-medium, line-height);
  color: $semantic-color-text-primary;
  cursor: text;

  &:focus {
    outline: 2px solid $semantic-color-focus;
    outline-offset: 2px;
    border-color: $semantic-color-primary;
  }

  p {
    margin: 0 0 $semantic-spacing-content-paragraph 0;

    &:last-child {
      margin-bottom: 0;
    }
  }

  strong {
    font-weight: $semantic-typography-font-weight-bold;
  }

  em {
    font-style: italic;
  }

  u {
    text-decoration: underline;
  }
}

.demo-table {
  width: 100%;
  border-collapse: collapse;
  background: $semantic-color-surface-primary;
  border-radius: $semantic-border-radius-lg;
  overflow: hidden;
  box-shadow: $semantic-shadow-elevation-1;

  th,
  td {
    padding: $semantic-spacing-component-sm $semantic-spacing-component-md;
    text-align: left;
    border-bottom: $semantic-border-width-1 solid $semantic-color-border-subtle;
    font-family: map-get($semantic-typography-body-medium, font-family);
    font-size: map-get($semantic-typography-body-medium, font-size);
    font-weight: map-get($semantic-typography-body-medium, font-weight);
    line-height: map-get($semantic-typography-body-medium, line-height);
  }

  th {
    background: $semantic-color-surface-secondary;
    color: $semantic-color-text-primary;
    font-weight: $semantic-typography-font-weight-semibold;
    position: sticky;
    top: 0;
  }

  td {
    color: $semantic-color-text-primary;
  }
}

.demo-table-row {
  cursor: pointer;
  transition: background-color $semantic-motion-duration-fast $semantic-motion-easing-ease;

  &:hover {
    background: $semantic-color-surface-elevated;
  }

  &--selected {
    background: $semantic-color-primary;
    color: $semantic-color-on-primary;

    td {
      color: $semantic-color-on-primary;
    }
  }

  &:last-child td {
    border-bottom: none;
  }
}

.demo-table-action {
  background: none;
  border: none;
  color: $semantic-color-text-secondary;
  font-size: $semantic-typography-font-size-lg;
  cursor: pointer;
  padding: $semantic-spacing-component-xs;
  border-radius: $semantic-border-radius-sm;
  transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease;

  &:hover {
    background: $semantic-color-surface-elevated;
    color: $semantic-color-text-primary;
  }

  &:focus-visible {
    outline: 2px solid $semantic-color-focus;
    outline-offset: 2px;
  }

  .demo-table-row--selected & {
    color: $semantic-color-on-primary;

    &:hover {
      background: rgba(255, 255, 255, 0.1);
    }
  }
}

.demo-controls {
  display: flex;
  flex-direction: column;
  gap: $semantic-spacing-component-md;
  padding: $semantic-spacing-component-lg;
  background: $semantic-color-surface-secondary;
  border-radius: $semantic-border-radius-lg;
  border: $semantic-border-width-1 solid $semantic-color-border-subtle;
}

.demo-control-group {
  display: flex;
  flex-wrap: wrap;
  gap: $semantic-spacing-component-md;

  label {
    display: flex;
    align-items: center;
    gap: $semantic-spacing-component-xs;
    font-family: map-get($semantic-typography-body-medium, font-family);
    font-size: map-get($semantic-typography-body-medium, font-size);
    font-weight: map-get($semantic-typography-body-medium, font-weight);
    line-height: map-get($semantic-typography-body-medium, line-height);
    color: $semantic-color-text-primary;
    cursor: pointer;
    user-select: none;

    input[type="checkbox"] {
      margin: 0;
      cursor: pointer;
    }
  }
}

.demo-output {
  margin-top: $semantic-spacing-layout-section-md;
  padding: $semantic-spacing-component-lg;
  background: $semantic-color-surface-secondary;
  border-radius: $semantic-border-radius-lg;
  border: $semantic-border-width-1 solid $semantic-color-border-subtle;

  h4 {
    font-family: map-get($semantic-typography-heading-h4, font-family);
    font-size: map-get($semantic-typography-heading-h4, font-size);
    font-weight: map-get($semantic-typography-heading-h4, font-weight);
    line-height: map-get($semantic-typography-heading-h4, line-height);
    color: $semantic-color-text-primary;
    margin: 0 0 $semantic-spacing-component-md 0;
  }
}

.demo-log {
  max-height: 200px;
  overflow-y: auto;
  background: $semantic-color-surface-primary;
  border: $semantic-border-width-1 solid $semantic-color-border-subtle;
  border-radius: $semantic-border-radius-md;
  padding: $semantic-spacing-component-sm;

  // Custom scrollbar styling
  scrollbar-width: thin;
  scrollbar-color: $semantic-color-border-subtle $semantic-color-surface-secondary;

  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-track {
    background: $semantic-color-surface-secondary;
    border-radius: $semantic-border-radius-sm;
  }

  &::-webkit-scrollbar-thumb {
    background: $semantic-color-border-subtle;
    border-radius: $semantic-border-radius-sm;

    &:hover {
      background: $semantic-color-border-primary;
    }
  }
}

.demo-log-entry {
  font-family: $semantic-typography-font-family-mono;
  font-size: map-get($semantic-typography-body-small, font-size);
  color: $semantic-color-text-primary;
  padding: $semantic-spacing-component-xs 0;
  border-bottom: $semantic-border-width-1 solid $semantic-color-border-subtle;

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

  &:first-child {
    color: $semantic-color-success;
    font-weight: $semantic-typography-font-weight-medium;
  }
}

.demo-log-empty {
  font-family: map-get($semantic-typography-body-medium, font-family);
  font-size: map-get($semantic-typography-body-medium, font-size);
  color: $semantic-color-text-secondary;
  text-align: center;
  padding: $semantic-spacing-component-md;
  font-style: italic;
}

// Responsive Design
@media (max-width: $semantic-breakpoint-md - 1) {
  .demo-container {
    padding: $semantic-spacing-layout-section-sm;
  }

  .demo-row {
    gap: $semantic-spacing-component-sm;
  }

  .demo-position-container {
    padding: $semantic-spacing-component-lg;
    gap: $semantic-spacing-component-md;
  }

  .demo-control-group {
    flex-direction: column;
    gap: $semantic-spacing-component-sm;
  }
}

@media (max-width: $semantic-breakpoint-sm - 1) {
  .demo-container {
    padding: $semantic-spacing-component-md;
  }

  .demo-section {
    margin-bottom: $semantic-spacing-layout-section-md;
  }

  .demo-row {
    flex-direction: column;
    gap: $semantic-spacing-component-sm;
  }

  .demo-context-area {
    padding: $semantic-spacing-component-md;
    min-height: 100px;
  }

  .demo-editor {
    min-height: 100px;
    padding: $semantic-spacing-component-sm;
  }

  .demo-table {
    font-size: map-get($semantic-typography-body-small, font-size);

    th,
    td {
      padding: $semantic-spacing-component-xs $semantic-spacing-component-sm;
    }
  }

  .demo-position-container {
    grid-template-areas: 
      "top"
      "left"
      "center"
      "right"
      "bottom";
    gap: $semantic-spacing-component-sm;
    padding: $semantic-spacing-component-md;
  }

  .demo-position-button {
    min-width: 60px;
  }
}

// High contrast support
@media (prefers-contrast: high) {
  .demo-trigger-button,
  .demo-position-button,
  .demo-table,
  .demo-context-area,
  .demo-editor,
  .demo-controls,
  .demo-output,
  .demo-log {
    border-width: $semantic-border-width-2;
  }
}

// Reduced motion support
@media (prefers-reduced-motion: reduce) {
  .demo-trigger-button,
  .demo-position-button,
  .demo-table-row,
  .demo-table-action,
  .demo-context-area {
    transition: none;
  }
}