/* ============================================================================
   PROFESSIONAL COMPONENTS
   Modern, accessible components following Material Design 3
   ============================================================================ */

/* Import animations */
@import url('animations.css');

/* Base Styles */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-family-body);
  background-color: var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Screen Reader Only - Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border-width: 0;
}

.sr-only-focusable:active,
.sr-only-focusable:focus {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 500;
  line-height: 1.2;
}

h1 {
  font: var(--font-display-large);
}

h2 {
  font: var(--font-headline-large);
}

h3 {
  font: var(--font-headline-medium);
}

h4 {
  font: var(--font-headline-small);
}

h5 {
  font: var(--font-title-large);
}

h6 {
  font: var(--font-title-medium);
}

p {
  font: var(--font-body-medium);
  margin: 0 0 var(--space-md) 0;
}

/* ============================================================================
   BUTTONS - Enhanced with micro-interactions
   ============================================================================ */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font: var(--font-label-large);
  font-weight: 600;
  cursor: pointer;
  transition: all 200ms ease;
  text-decoration: none;
  user-select: none;
  overflow: hidden;
  user-select: none;
}

/* Ripple effect on click */
.btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.btn:active::before {
  width: 300px;
  height: 300px;
}

.btn:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--elevation-level1);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--md-sys-color-primary);
  box-shadow: var(--elevation-level3);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: var(--elevation-level1);
}

.btn-secondary {
  background-color: var(--md-sys-color-surface-variant);
  color: var(--md-sys-color-on-surface-variant);
  border: 1px solid var(--md-sys-color-outline);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  box-shadow: var(--elevation-level2);
  transform: translateY(-1px);
}

.btn-secondary:active {
  transform: translateY(0);
}

.btn-icon {
  padding: var(--space-sm);
  border-radius: var(--shape-corner-xs);
  background-color: transparent;
  color: var(--md-sys-color-on-surface-variant);
}

.btn-icon:hover:not(:disabled) {
  background-color: var(--md-sys-color-surface-variant);
}

/* Cards */
.card {
  background-color: var(--md-sys-color-surface);
  border-radius: var(--shape-corner-md);
  box-shadow: var(--elevation-level1);
  padding: var(--space-md);
  transition: box-shadow var(--motion-duration-short) var(--motion-easing-standard);
}

.card:hover {
  box-shadow: var(--elevation-level2);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.card-title {
  font: var(--font-title-large);
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.card-subtitle {
  font: var(--font-body-medium);
  color: var(--md-sys-color-on-surface-variant);
}

/* Form Elements */
.form-group {
  margin-bottom: var(--space-md);
}

.form-label {
  display: block;
  font: var(--font-label-large);
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  margin-bottom: var(--space-xs);
}

.form-input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--shape-corner-sm);
  background-color: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font: var(--font-body-medium);
  transition: border-color var(--motion-duration-short) var(--motion-easing-standard);
}

.form-input:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.2);
}

.form-input::placeholder {
  color: var(--md-sys-color-on-surface-variant);
}

.form-select {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--shape-corner-sm);
  background-color: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font: var(--font-body-medium);
  cursor: pointer;
}

.form-checkbox {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
}

.form-checkbox input[type="checkbox"] {
  width: 20px;
  height: 20px;
  border: 2px solid var(--md-sys-color-outline);
  border-radius: var(--shape-corner-xs);
  background-color: var(--md-sys-color-surface);
  cursor: pointer;
  transition: all var(--motion-duration-short) var(--motion-easing-standard);
}

.form-checkbox input[type="checkbox"]:checked {
  background-color: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
}

/* Status Indicators */
.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  margin-right: var(--space-xs);
}

.status-idle {
  background-color: var(--md-sys-color-outline);
}

.status-running {
  background-color: var(--md-sys-color-warning);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-success {
  background-color: var(--md-sys-color-success);
}

.status-error {
  background-color: var(--md-sys-color-error);
}

.status-disabled {
  background-color: var(--md-sys-color-outline-variant);
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--shape-corner-xs);
  font: var(--font-label-medium);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-primary {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.badge-secondary {
  background-color: var(--md-sys-color-surface-variant);
  color: var(--md-sys-color-on-surface-variant);
}

.badge-success {
  background-color: var(--md-sys-color-success);
  color: var(--md-sys-color-on-success);
}

.badge-warning {
  background-color: var(--md-sys-color-warning);
  color: var(--md-sys-color-on-warning);
}

.badge-error {
  background-color: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}

/* Progress Bar */
.progress-bar {
  width: 100%;
  height: 8px;
  background-color: var(--md-sys-color-surface-variant);
  border-radius: var(--shape-corner-xs);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background-color: var(--md-sys-color-primary);
  border-radius: var(--shape-corner-xs);
  transition: width var(--motion-duration-medium) var(--motion-easing-standard);
}

/* Loading Spinner */
.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--md-sys-color-surface-variant);
  border-top: 2px solid var(--md-sys-color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn var(--motion-duration-short) var(--motion-easing-standard);
}

.modal[hidden] {
  display: none !important;
}

.modal-content {
  background-color: var(--md-sys-color-surface);
  border-radius: var(--shape-corner-lg);
  box-shadow: var(--elevation-level5);
  max-width: 90%;
  max-height: 90%;
  overflow: hidden;
  animation: slideUp var(--motion-duration-medium) var(--motion-easing-decelerated);
  pointer-events: auto;
  position: relative;
  z-index: 1001;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.modal-title {
  font: var(--font-headline-small);
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--shape-corner-xs);
  background-color: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background-color var(--motion-duration-short) var(--motion-easing-standard);
}

.modal-close:hover {
  background-color: var(--md-sys-color-surface-variant);
}

.modal-body {
  padding: var(--space-md);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-md);
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  left: auto;
  /* Shrink-to-fit, but never wider than the viewport allows. It used to be
     right-anchored with no width bound at all, so a 300px-minimum toast on a
     narrow screen extended past the right edge and dragged the whole page
     sideways with it — the horizontal scroll appeared on every page that
     showed a toast, which is every page that reports an error. */
  max-width: min(26rem, calc(100vw - 2 * var(--space-lg)));
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-sm);
  pointer-events: none;
}

.toast-container > * {
  pointer-events: auto;
  max-width: 100%;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-md);
  background-color: var(--md-sys-color-surface);
  border-radius: var(--shape-corner-md);
  box-shadow: var(--elevation-level3);
  min-width: 0;
  max-width: 100%;
  animation: slideInRight var(--motion-duration-medium) var(--motion-easing-decelerated);
}

.toast-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--shape-corner-xs);
  flex-shrink: 0;
}

.toast-success .toast-icon {
  background-color: var(--md-sys-color-success);
  color: var(--md-sys-color-on-success);
}

.toast-error .toast-icon {
  background-color: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}

.toast-warning .toast-icon {
  background-color: var(--md-sys-color-warning);
  color: var(--md-sys-color-on-warning);
}

.toast-info .toast-icon {
  background-color: var(--md-sys-color-info);
  color: var(--md-sys-color-on-info);
}

.toast-content {
  flex: 1;
}

.toast-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: none;
  background: none;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  border-radius: var(--shape-corner-xs);
  transition: background-color var(--motion-duration-short) var(--motion-easing-standard);
  padding: 0;
  margin-left: var(--space-xs);
}

.toast-close:hover {
  background-color: var(--md-sys-color-surface-variant);
}

.toast-close .material-icons {
  font-size: 16px;
}

.toast-title {
  font: var(--font-label-large);
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  margin-bottom: var(--space-xs);
}

.toast-message {
  font: var(--font-body-small);
  color: var(--md-sys-color-on-surface-variant);
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slideInRight {
  from {
    transform: translateX(20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Responsive Utilities */
@media (max-width: 768px) {
  .btn {
    padding: var(--space-sm) var(--space-md);
    font: var(--font-label-medium);
  }
  
  .modal-content {
    margin: var(--space-md);
    max-width: calc(100% - var(--space-lg));
  }
  
  .toast-container {
    top: var(--space-md);
    right: var(--space-md);
    left: var(--space-md);
  }
  
  .toast {
    min-width: auto;
    max-width: none;
  }
}

/* ── Status filter ──────────────────────────────────────────────────────────
 * Owner of the six-checkbox order-status filter used by the sync and settings
 * pages. Replaces ~50 lines of repeated inline styles per copy.
 */
.status-filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: var(--space-sm);
}

.status-filter-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
}

.status-filter-option:hover {
  background: var(--md-sys-color-surface-variant);
}

.status-filter-option input {
  width: 18px;
  height: 18px;
  cursor: pointer;
  flex: none;
}

.status-filter-option input:focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 2px;
}

.status-filter-text {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  color: var(--color-foreground);
  flex-wrap: wrap;
}

.status-chip {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  white-space: nowrap;
}

.status-chip--warn     { background: var(--md-sys-color-warning-container, #FEF3C7); color: var(--md-sys-color-on-warning-container, #92400E); }
.status-chip--info     { background: var(--md-sys-color-info-container, #DBEAFE);    color: var(--md-sys-color-on-info-container, #1E40AF); }
.status-chip--progress { background: var(--md-sys-color-secondary-container, #E0E7FF); color: var(--md-sys-color-on-secondary-container, #3730A3); }
.status-chip--ok       { background: var(--md-sys-color-success-container, #D1FAE5);  color: var(--md-sys-color-on-success-container, #065F46); }
.status-chip--bad      { background: var(--md-sys-color-error-container);             color: var(--md-sys-color-on-error-container); }
