// Import Sass color module
@use 'sass:color';

// Variables
$primary-color: #2271b1;
$secondary-color: #50575e;
$success-color: #46b450;
$warning-color: #ffb900;
$danger-color: #dc3232;
$light-bg: #f0f0f1;
$dark-bg: #23282d;
$border-color: #dcdcde;
$text-color: #3c434a;
$white: #ffffff;

// Mixins
@mixin card-shadow {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

@mixin transition($property: all) {
  transition: $property 0.2s ease;
}

// Base Styles
.roadmap-app {
  // Accent colour: adopt the active theme's brand colour when it exposes one.
  // BuddyX / BuddyX-Pro and Reign both set --wp--preset--color--primary; fall
  // back to the plugin default so the board looks correct on any theme.
  --roadmap-accent: var(--wp--preset--color--primary, #{$primary-color});
  --roadmap-accent-hover: color-mix(in srgb, var(--roadmap-accent) 85%, #000);
  --roadmap-accent-tint: color-mix(in srgb, var(--roadmap-accent) 15%, #fff);

  // Foreground colour for text/icons placed ON an accent-coloured background.
  // Defaults to white (correct for the plugin's default mid-blue). Where the
  // browser supports OKLCH relative colour, flip to black on LIGHT theme accents
  // (e.g. Reign's pale #97c0ee) and keep white on dark ones - readable, premium
  // buttons on ANY theme accent.
  --roadmap-accent-contrast: #{$white};

  // Accent-coloured TEXT/emphasis placed on a surface or tint (stat numbers,
  // chips, "voted" state, links). The raw theme accent washes out as text on a
  // same-mode surface when it is pale (Reign #97c0ee on a light card). The
  // @supports block below keeps the accent hue but clamps its lightness so it
  // stays readable in both modes; this is the pre-OKLCH fallback.
  --roadmap-accent-text: var(--roadmap-accent-hover);

  // Chrome tokens (light values; the dark theme block swaps them). Every view
  // template reads these so light/dark is a pure token swap.
  --rm-surface: #{$white};
  --rm-surface-alt: #f6f7f7;
  --rm-elevated: #{$white};
  --rm-border: #e5e7eb;
  --rm-border-soft: #f0f1f3;
  --rm-heading: #1f2937;
  --rm-text: #3c434a;
  --rm-muted: #6b7280;

  // Semantic status palette: a solid (text / card border) and a tint (chip
  // background) per status. Kept distinct on purpose so status reads at a glance.
  // Solids are tuned so the badge text clears WCAG AA (>=4.5:1) on its own tint.
  --rm-planned: #2563eb;   --rm-planned-tint: #e8f0fe;
  --rm-progress: #b45309;  --rm-progress-tint: #fef1e0;
  --rm-hold: #475569;      --rm-hold-tint: #eef1f4;
  --rm-review: #7c3aed;    --rm-review-tint: #f3e9fd;
  --rm-done: #15803d;      --rm-done-tint: #e6f5ec;
  --rm-cancelled: #b91c1c; --rm-cancelled-tint: #fdeaea;

  // Priority palette (a separate scale from status): low..critical.
  --rm-priority-low: #176e2f;      --rm-priority-low-tint: #d9f4e1;
  --rm-priority-medium: #7a5f0a;   --rm-priority-medium-tint: #fdf3d3;
  --rm-priority-high: #92400e;     --rm-priority-high-tint: #fde8cf;
  --rm-priority-critical: #b42318; --rm-priority-critical-tint: #fbe2e0;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: $text-color;
  line-height: 1.6;
  
  * {
    box-sizing: border-box;
  }
}

// Luminance-adaptive accent contrast (kept top-level so it overrides the plain
// --roadmap-accent-contrast above by source order, without triggering Sass's
// mixed-decls warning). Black text on light theme accents, white on dark ones.
@supports (color: oklch(from red l c h)) {
  .roadmap-app {
    --roadmap-accent-contrast: oklch(from var(--roadmap-accent) clamp(0, (0.72 - l) * 1000, 1) 0 0);
  }
}

// Accent TEXT/emphasis, hue-preserved but lightness-clamped so it stays readable
// as text on a surface/tint. Light mode caps lightness (dark enough on light
// surfaces); dark mode floors it (light enough on dark surfaces). The dark
// selectors out-specify the light rule so they win when the theme is dark.
@supports (color: oklch(from red l c h)) {
  .roadmap-app {
    --roadmap-accent-text: oklch(from var(--roadmap-accent) min(l, 0.5) c h);
  }

  .roadmap-dark,
  html[data-bx-mode="dark"] .roadmap-app,
  html[data-mode="dark"] .roadmap-app,
  body.buddyx-dark-theme .roadmap-app,
  body.buddyx-dark-style-variation .roadmap-app,
  body.dark-scheme .roadmap-app,
  body.reign-ld-dark-theme .roadmap-app {
    --roadmap-accent-text: oklch(from var(--roadmap-accent) max(l, 0.62) c h);
  }
}

.roadmap-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

// Typography
.roadmap-title {
  font-size: 24px;
  font-weight: 600;
  margin: 0 0 20px;
}

.roadmap-subtitle {
  font-size: 18px;
  font-weight: 500;
  margin: 0 0 15px;
}

// Buttons
.roadmap-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  @include transition();
  
  &:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }
  
  &-primary {
    background: var(--roadmap-accent);
    color: var(--roadmap-accent-contrast, #{$white});
    border-color: var(--roadmap-accent);

    &:hover:not(:disabled) {
      background: var(--roadmap-accent-hover);
      border-color: var(--roadmap-accent-hover);
    }
  }
  
  &-secondary {
    background: $white;
    color: $text-color;
    border-color: $border-color;
    
    &:hover:not(:disabled) {
      background: $light-bg;
    }
  }
  
  &-success {
    background: $success-color;
    color: $white;
    border-color: $success-color;
    
    &:hover:not(:disabled) {
      background: color.adjust($success-color, $lightness: -10%);
    }
  }
  
  &-danger {
    background: $danger-color;
    color: $white;
    border-color: $danger-color;
    
    &:hover:not(:disabled) {
      background: color.adjust($danger-color, $lightness: -10%);
    }
  }
  
  &-sm {
    padding: 4px 12px;
    font-size: 13px;
  }
  
  &-icon {
    padding: 8px;
    
    &.roadmap-btn-sm {
      padding: 4px;
    }
  }
}

// Forms
.roadmap-form {
  &-group {
    margin-bottom: 20px;
  }
  
  &-label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    font-size: 14px;
  }
  
  &-control {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.5;
    color: $text-color;
    background-color: $white;
    border: 1px solid $border-color;
    border-radius: 4px;
    @include transition(border-color);
    
    &:focus {
      outline: none;
      border-color: var(--roadmap-accent);
      box-shadow: 0 0 0 1px var(--roadmap-accent);
    }
    
    &:disabled {
      background-color: $light-bg;
      cursor: not-allowed;
    }
  }
  
  &-help {
    margin-top: 5px;
    font-size: 13px;
    color: $secondary-color;
  }
}

// Loading
.roadmap-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: $secondary-color;
  
  p {
    margin-top: 20px;
    font-size: 16px;
  }
}

// Error
.roadmap-error {
  text-align: center;
  padding: 40px 20px;
  background: color.adjust($danger-color, $lightness: 45%);
  border: 1px solid color.adjust($danger-color, $lightness: 30%);
  border-radius: 4px;
  color: $danger-color;
  
  p {
    margin: 0 0 20px;
  }
}

// Empty State
.roadmap-empty {
  text-align: center;
  padding: 60px 20px;
  color: $secondary-color;
  
  p {
    margin: 0 0 20px;
    font-size: 16px;
  }
}

// Cards
.roadmap-card {
  background: $white;
  border: 1px solid $border-color;
  border-radius: 4px;
  padding: 20px;
  @include card-shadow();
  @include transition();
  
  &:hover {
    @include card-shadow();
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  }
}

// Grid
.roadmap-grid {
  display: grid;
  gap: 20px;
  
  &-cols-2 {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }
  
  &-cols-3 {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }
  
  &-cols-4 {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}

// Badges
.roadmap-badge {
  display: inline-block;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  border-radius: 3px;
  
  &-primary {
    background: var(--roadmap-accent-tint);
    // Lightness-clamped accent text so the chip keeps its accent identity while
    // staying readable on the tint in both modes (the raw accent washed out
    // against its own tint on pale theme accents).
    color: var(--roadmap-accent-text);
  }
  
  &-success {
    background: var(--rm-priority-low-tint);
    color: var(--rm-priority-low);
  }

  &-warning {
    background: var(--rm-priority-medium-tint);
    color: var(--rm-priority-medium);
  }

  &-danger {
    background: var(--rm-priority-critical-tint);
    color: var(--rm-priority-critical);
  }
}

// Semantic status badges (shared by every view template). A status taxonomy
// slug maps to the status palette so the same status reads the same colour on
// the board, cards, list and timeline - and swaps for dark via tokens. Scoped
// to .roadmap-badge so it never touches other status-classed elements (e.g. the
// minimal template's status dots). Unknown slugs fall back to the neutral chip.
.roadmap-badge {
  &[class*="roadmap-status-"] {
    background: var(--rm-hold-tint);
    color: var(--rm-hold);
  }
  &.roadmap-status-planned,
  &.roadmap-status-approved,
  &.roadmap-status-backlog {
    background: var(--rm-planned-tint);
    color: var(--rm-planned);
  }
  &.roadmap-status-in-progress,
  &.roadmap-status-inprogress,
  &.roadmap-status-in-development,
  &.roadmap-status-development,
  &.roadmap-status-started {
    background: var(--rm-progress-tint);
    color: var(--rm-progress);
  }
  &.roadmap-status-on-hold,
  &.roadmap-status-onhold,
  &.roadmap-status-paused,
  &.roadmap-status-deferred {
    background: var(--rm-hold-tint);
    color: var(--rm-hold);
  }
  &.roadmap-status-under-review,
  &.roadmap-status-review,
  &.roadmap-status-reviewing,
  &.roadmap-status-idea,
  &.roadmap-status-considering {
    background: var(--rm-review-tint);
    color: var(--rm-review);
  }
  &.roadmap-status-completed,
  &.roadmap-status-complete,
  &.roadmap-status-done,
  &.roadmap-status-released,
  &.roadmap-status-shipped,
  &.roadmap-status-launched {
    background: var(--rm-done-tint);
    color: var(--rm-done);
  }
  &.roadmap-status-cancelled,
  &.roadmap-status-canceled,
  &.roadmap-status-rejected,
  &.roadmap-status-declined,
  &.roadmap-status-wont-do,
  &.roadmap-status-closed {
    background: var(--rm-cancelled-tint);
    color: var(--rm-cancelled);
  }
}

// Modal
.roadmap-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  
  &-dialog {
    background: $white;
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    @include card-shadow();
  }
  
  &-header {
    padding: 20px;
    border-bottom: 1px solid $border-color;
    display: flex;
    align-items: center;
    justify-content: space-between;
    
    h3 {
      margin: 0;
      font-size: 18px;
      font-weight: 600;
    }
  }
  
  &-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
  }
  
  &-footer {
    padding: 20px;
    border-top: 1px solid $border-color;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
  }
}

// Icons
.roadmap-icon {
  width: 20px;
  height: 20px;
  display: inline-block;
  vertical-align: middle;
  fill: currentColor;
  
  &-sm {
    width: 16px;
    height: 16px;
  }
  
  &-lg {
    width: 24px;
    height: 24px;
  }
}

// Dark Mode
// Shared dark styles, applied both by the plugin's own toggle (.roadmap-dark)
// and automatically when the active theme is in dark mode.
@mixin roadmap-dark-theme {
  // Swap the chrome + status tokens to dark-appropriate values. Because every
  // view template reads these tokens, this single block darkens them all.
  --rm-surface: #{color.adjust($dark-bg, $lightness: 6%)};
  --rm-surface-alt: #{$dark-bg};
  --rm-elevated: #{color.adjust($dark-bg, $lightness: 9%)};
  --rm-border: #{color.adjust($dark-bg, $lightness: 14%)};
  --rm-border-soft: #{color.adjust($dark-bg, $lightness: 9%)};
  --rm-heading: #e2e4e7;
  --rm-text: #d3d6da;
  --rm-muted: #9ca3af;
  --rm-planned: #60a5fa;   --rm-planned-tint: #1c2740;
  --rm-progress: #fbbf24;  --rm-progress-tint: #2c2416;
  --rm-hold: #94a3b8;      --rm-hold-tint: #262b32;
  --rm-review: #c084fc;    --rm-review-tint: #251a35;
  --rm-done: #4ade80;      --rm-done-tint: #14281b;
  --rm-cancelled: #f87171; --rm-cancelled-tint: #2c1a1a;
  --rm-priority-low: #4ade80;      --rm-priority-low-tint: #14281b;
  --rm-priority-medium: #fbbf24;   --rm-priority-medium-tint: #2c2416;
  --rm-priority-high: #fb923c;     --rm-priority-high-tint: #2c1f14;
  --rm-priority-critical: #f87171; --rm-priority-critical-tint: #2c1a1a;

  // Make the accent tint dark-mode-aware (light mode leaves it near-white),
  // so tinted chips read as a subtle dark-accent surface on a dark card instead
  // of a glaring near-white block. Accent text then follows the same swap.
  --roadmap-accent-tint: color-mix(in srgb, var(--roadmap-accent) 22%, #1a1d21);
  --roadmap-accent-text: var(--roadmap-accent);

  background: $dark-bg;
  color: #e2e4e7;

  // Headings and item titles otherwise use a dark light-mode text colour, which
  // becomes invisible on a dark surface.
  h1, h2, h3, h4, h5, h6,
  [class*="-title"],
  [class*="-heading"],
  [class*="-count"],
  [class*="-name"] {
    color: #e2e4e7;
  }

  .roadmap-card,
  .roadmap-modal-dialog,
  [class*="-column"],
  [class*="-item"] {
    background: color.adjust($dark-bg, $lightness: 5%);
    border-color: color.adjust($dark-bg, $lightness: 10%);
    color: #e2e4e7;
  }

  .roadmap-form-control {
    background: color.adjust($dark-bg, $lightness: 10%);
    border-color: color.adjust($dark-bg, $lightness: 15%);
    color: #e2e4e7;

    &:focus {
      border-color: $primary-color;
    }
  }

  .roadmap-btn-secondary {
    background: color.adjust($dark-bg, $lightness: 10%);
    border-color: color.adjust($dark-bg, $lightness: 15%);
    color: #e2e4e7;

    &:hover:not(:disabled) {
      background: color.adjust($dark-bg, $lightness: 15%);
    }
  }
}

// The plugin's own dark toggle.
.roadmap-dark {
  @include roadmap-dark-theme;
}

// Follow the active theme's dark mode, driven ONLY by the theme's own
// light/dark toggle (never the OS / prefers-color-scheme). BuddyX / BuddyX-Pro
// and Reign flip html[data-bx-mode="dark"] and set a body dark class when the
// user toggles dark from the theme header.
html[data-bx-mode="dark"] .roadmap-app,
html[data-mode="dark"] .roadmap-app,
body.buddyx-dark-theme .roadmap-app,
body.buddyx-dark-style-variation .roadmap-app,
body.dark-scheme .roadmap-app,
body.reign-ld-dark-theme .roadmap-app {
  @include roadmap-dark-theme;
}

// Checkbox Group
.roadmap-checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.roadmap-checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  
  input[type="checkbox"] {
    cursor: pointer;
  }
  
  &:hover {
    color: $primary-color;
  }
}

// Responsive
@media (max-width: 768px) {
  .roadmap-container {
    padding: 10px;
  }
  
  .roadmap-grid {
    &-cols-2,
    &-cols-3,
    &-cols-4 {
      grid-template-columns: 1fr;
    }
  }
  
  .roadmap-modal-dialog {
    width: 95%;
    margin: 10px;
  }
}