/* ===== THEME SYSTEM ===== */
/* CSS Custom Properties for Theme Support */
:root {
  /* Light Theme (Default) */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #e9ecef;
  --text-primary: #212529;
  --text-secondary: #6c757d;
  --text-muted: #adb5bd;
  --border-color: #dee2e6;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --accent-sky: #87ceeb;
  --accent-blue: #1e90ff;
  --accent-orange: #ffa500;
  --accent-orange-dark: #ff8c00;
  --accent-teal: #20b2aa;
  --success-color: #28a745;
  --warning-color: #ffc107;
  --error-color: #dc3545;
  --card-bg: #ffffff;
  --input-bg: #ffffff;
  --button-bg: #f8f9fa;
  --button-hover: #e9ecef;
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-primary: #1a1a1a;
  --bg-secondary: #2d2d2d;
  --bg-tertiary: #404040;
  --text-primary: #ffffff;
  --text-secondary: #cccccc;
  --text-muted: #888888;
  --border-color: #555555;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --accent-sky: #5dade2;
  --accent-blue: #3498db;
  --accent-orange: #f39c12;
  --accent-orange-dark: #e67e22;
  --accent-teal: #48c9b0;
  --success-color: #27ae60;
  --warning-color: #f1c40f;
  --error-color: #e74c3c;
  --card-bg: #2d2d2d;
  --input-bg: #404040;
  --button-bg: #404040;
  --button-hover: #555555;
}

/* ===== DASHBOARD THEME APPLICATION ===== */
.dashboard-container {
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.3s ease, color 0.3s ease;
}

.dashboard-header {
  .dashboard-title {
    color: var(--text-primary);
  }

  .dashboard-subtitle {
    color: var(--text-secondary);
  }
}

/* Control Elements */
.dashboard-controls {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1rem;

  .control-group {
    label {
      color: var(--text-primary);
      font-weight: 600;
    }

    .control-select,
    .control-input {
      background: var(--input-bg);
      border: 1px solid var(--border-color);
      color: var(--text-primary);
      border-radius: 4px;
      padding: 0.5rem;
      transition: border-color 0.2s ease, box-shadow 0.2s ease;

      &:focus {
        outline: none;
        border-color: var(--accent-sky);
        box-shadow: 0 0 0 2px rgba(135, 206, 235, 0.2);
      }

      &::placeholder {
        color: var(--text-muted);
      }
    }

    .control-button {
      background: var(--button-bg);
      border: 1px solid var(--border-color);
      color: var(--text-primary);
      border-radius: 4px;
      padding: 0.5rem 1rem;
      cursor: pointer;
      transition: all 0.2s ease;

      &:hover {
        background: var(--button-hover);
        border-color: var(--accent-sky);
      }

      &:focus {
        outline: none;
        border-color: var(--accent-sky);
        box-shadow: 0 0 0 2px rgba(135, 206, 235, 0.2);
      }

      &:disabled {
        opacity: 0.6;
        cursor: not-allowed;
      }

      &.theme-toggle {
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;

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

/* Dashboard Cards */
.dashboard-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 2px 8px var(--shadow-color);
  transition: all 0.3s ease;

  &:hover {
    box-shadow: 0 4px 16px var(--shadow-color);
    border-color: var(--accent-sky);
  }

  .card-header-custom {
    border-bottom: 1px solid var(--border-color);

    .card-title {
      color: var(--text-primary);

      .card-icon {
        color: var(--accent-sky);
      }
    }
  }

  .stats-grid {
    .stat-item {
      .stat-value {
        color: var(--text-primary);
      }

      .stat-label {
        color: var(--text-secondary);
      }
    }
  }

  .task-list {
    .task-item {
      background: var(--bg-secondary);
      border: 1px solid var(--border-color);
      border-radius: 6px;
      transition: all 0.2s ease;

      &:hover {
        background: var(--bg-tertiary);
        border-color: var(--accent-sky);
      }

      &.completed {
        opacity: 0.7;
        text-decoration: line-through;

        .task-checkbox {
          background: var(--success-color);
          border-color: var(--success-color);

          &::after {
            content: '✓';
            color: white;
            font-size: 0.8rem;
            display: flex;
            align-items: center;
            justify-content: center;
          }
        }
      }

      .task-title {
        color: var(--text-primary);
      }

      .task-meta {
        color: var(--text-secondary);
      }

      .task-checkbox {
        border: 2px solid var(--border-color);
        background: var(--bg-primary);
        border-radius: 4px;
        width: 20px;
        height: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
      }
    }
  }

  .message-list {
    .message-item {
      background: var(--bg-secondary);
      border: 1px solid var(--border-color);
      border-radius: 6px;
      transition: all 0.2s ease;

      &:hover {
        background: var(--bg-tertiary);
        border-color: var(--accent-sky);
      }

      .message-name {
        color: var(--text-primary);
      }

      .message-text {
        color: var(--text-secondary);
      }

      .message-avatar {
        background: var(--accent-sky);
        color: white;
      }
    }
  }
}

/* Progress Circles */
.progress-circle-modern {
  .bg {
    fill: var(--bg-tertiary);
  }

  .progress {
    stroke: var(--accent-sky);
  }
}

/* Modal Styles */
.modal-overlay {
  background: rgba(0, 0, 0, 0.8);

  .modal-content {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);

    .modal-close {
      background: var(--button-bg);
      border: 1px solid var(--border-color);
      color: var(--text-primary);

      &:hover {
        background: var(--button-hover);
        border-color: var(--error-color);
        color: var(--error-color);
      }
    }
  }
}

/* Accessibility Enhancements */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 8px;
  text-decoration: none;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  z-index: 100;
  transition: top 0.2s ease;

  &:focus {
    top: 6px;
  }
}

/* Focus Management */
.dashboard-card:focus-within,
.control-select:focus,
.control-input:focus,
.control-button:focus {
  outline: 2px solid var(--accent-sky);
  outline-offset: 2px;
}

/* ===== LEGACY PHASE 1 STYLES ===== */
/* Card Resizing and Pinning */
.resize-handle {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  background: var(--bg-primary);
  border: 2px solid var(--accent-sky);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: nw-resize;
  opacity: 0;
  transition: all 0.2s ease;
  z-index: 10;

  i {
    font-size: 0.75rem;
    color: var(--accent-sky);
  }

  &:hover,
  &:focus {
    opacity: 1;
    background: var(--accent-sky);
    border-color: var(--accent-blue);

    i {
      color: white;
    }
  }
}

.pin-button {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  background: var(--bg-primary);
  border: 2px solid var(--accent-orange);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 10;

  i {
    font-size: 0.875rem;
    color: var(--accent-orange);
  }

  &:hover,
  &:focus {
    background: var(--accent-orange);
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(255, 165, 0, 0.3);

    i {
      color: white;
    }
  }

  &[aria-pressed="true"] {
    background: var(--accent-orange);
    border-color: var(--accent-orange-dark);

    i {
      color: white;
    }
  }
}

.dashboard-card {
  position: relative;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  &:hover {
    .resize-handle,
    .pin-button {
      opacity: 0.8;
    }
  }

  &.resizing {
    box-shadow: 0 8px 32px rgba(135, 206, 235, 0.4);
    border-color: var(--accent-sky);
    transform: scale(1.02);

    .resize-handle {
      opacity: 1;
      background: var(--accent-sky);

      i {
        color: white;
      }
    }
  }

  &.pinned {
    order: -1;
    border-color: var(--accent-orange);
    box-shadow: 0 4px 20px rgba(255, 165, 0, 0.2);

    &::before {
      background: linear-gradient(90deg, var(--accent-orange), var(--accent-orange-dark), var(--accent-teal));
    }

    .pin-button {
      background: var(--accent-orange);

      i {
        color: white;
      }
    }
  }

  // Custom sizes for resized cards
  &[style*="width"] {
    grid-column: span 2;
    min-width: 300px;
  }

  &[style*="height"] {
    min-height: 200px;
  }
}

/* Enhanced Grid Layout for Resized Cards */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 2rem;
  margin-bottom: 2rem;

  // Adjust for resized cards
  .dashboard-card[style*="width"] {
    grid-column: span 2;
  }

  .dashboard-card[style*="width"][style*="height"] {
    grid-row: span 2;
  }
}

/* Responsive adjustments for card controls */
@media (max-width: 768px) {
  .resize-handle,
  .pin-button {
    opacity: 0.6;
  }

  .dashboard-card:hover {
    .resize-handle,
    .pin-button {
      opacity: 1;
    }
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .resize-handle,
  .pin-button {
    border-width: 3px;
  }

  .dashboard-card.pinned {
    border-width: 3px;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .resize-handle,
  .pin-button,
  .dashboard-card.resizing {
    transition: none;
  }
}

/* Focus management for card controls */
.resize-handle:focus,
.pin-button:focus {
  outline: 2px solid var(--accent-sky);
  outline-offset: 2px;
}

/* Visual feedback for pinned cards */
.pinned-indicator {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  background: var(--accent-orange);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);

  i {
    font-size: 0.75rem;
    color: white;
  }
}

/* Loading states for resizing */
.dashboard-card.resizing {
  pointer-events: none;

  * {
    pointer-events: none;
  }
}

/* Grid adjustments for different screen sizes */
@media (max-width: 1200px) {
  .dashboard-grid {
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  }
}

@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 1rem;

    .dashboard-card[style*="width"] {
      grid-column: span 1;
    }
  }
}

/* Print styles for pinned cards */
@media print {
  .dashboard-card.pinned {
    border: 2px solid #000;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .resize-handle,
  .pin-button {
    display: none !important;
  }
}
