/* Responsive Design for StartPage */

/* Mobile First Approach */

/* Small screens (up to 640px) */
@media (max-width: 640px) {
  .app-container {
    grid-template-columns: 1fr;
    grid-template-areas: 
      "header"
      "main";
  }
  
  .widget-panel {
    display: none;
  }
  
  .top-app-bar-content {
    padding: 8px 12px;
  }
  
  .app-title {
    font: var(--md-sys-typescale-title-medium);
    margin-left: 12px;
  }
  
  .main-content {
    padding: 16px 12px;
  }
  
  .collections-container {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .collection-header {
    padding: 12px;
  }
  
  .collection-title {
    font: var(--md-sys-typescale-title-small);
  }
  
  .collection-bookmarks {
    padding: 8px;
  }
  
  .bookmark-item {
    padding: 12px 8px;
    margin-bottom: 2px;
  }
  
  .bookmark-favicon {
    width: 18px;
    height: 18px;
  }
  
  .bookmark-title {
    font: var(--md-sys-typescale-body-small);
  }
  
  .bookmark-url {
    font: var(--md-sys-typescale-label-small);
  }
  
  .fab {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
  }
  
  /* Search overlay adjustments */
  .search-overlay {
    padding-top: 5vh;
  }
  
  .search-container {
    margin: 0 16px;
  }
  
  .search-input-container {
    padding: 6px 12px;
  }
  
  .search-result-item {
    padding: 12px;
  }
  
  /* Dialog adjustments */
  .dialog {
    width: 95vw;
    max-width: none;
    margin: 0;
  }
  
  .dialog-content {
    padding: 20px;
  }
  
  .dialog-actions {
    flex-direction: column;
    gap: 12px;
  }
  
  .dialog-actions .button {
    width: 100%;
  }
  
  /* Navigation drawer adjustments */
  .navigation-drawer {
    width: 280px;
    left: -280px;
  }
  
  /* User menu adjustments */
  .dropdown-menu {
    right: 8px;
    min-width: 180px;
  }
  
  /* Snackbar adjustments */
  .snackbar {
    left: 16px;
    right: 16px;
    transform: translateY(100px);
    min-width: auto;
    max-width: none;
  }
  
  .snackbar.show {
    transform: translateY(0);
  }
}

/* Medium screens (641px to 1024px) - Tablets */
@media (min-width: 641px) and (max-width: 1024px) {
  .app-container {
    grid-template-columns: 1fr;
    grid-template-areas: 
      "header"
      "main";
  }
  
  .widget-panel {
    display: none;
  }
  
  .main-content {
    padding: 20px;
  }
  
  .collections-container {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
  }
  
  .fab {
    bottom: 20px;
    right: 20px;
  }
  
  /* Show widget panel as overlay on tablet when needed */
  .widget-panel.mobile-overlay {
    display: block;
    position: fixed;
    top: 64px;
    right: -320px;
    height: calc(100vh - 64px);
    z-index: 150;
    transition: right var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized);
  }
  
  .widget-panel.mobile-overlay.open {
    right: 0;
    box-shadow: var(--md-sys-elevation-3);
  }
}

/* Large screens (1025px to 1440px) - Desktop */
@media (min-width: 1025px) and (max-width: 1440px) {
  .app-container {
    grid-template-columns: 1fr 320px;
    grid-template-areas: 
      "header header"
      "main widgets";
  }
  
  .widget-panel {
    display: block;
  }
  
  .main-content {
    padding: 24px;
  }
  
  .collections-container {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
  }
}

/* Extra large screens (1441px and up) - Large Desktop */
@media (min-width: 1441px) {
  .app-container {
    grid-template-columns: 1fr 360px;
    grid-template-areas: 
      "header header"
      "main widgets";
  }
  
  .widget-panel {
    width: 360px;
  }
  
  .main-content {
    padding: 32px;
    max-width: 1200px;
    margin: 0 auto;
  }
  
  .collections-container {
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 32px;
  }
  
  .collection {
    min-height: 300px;
  }
}

/* Ultra-wide screens (1920px and up) */
@media (min-width: 1920px) {
  .main-content {
    max-width: 1400px;
  }
  
  .collections-container {
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  }
}

/* Height-specific adjustments */
@media (max-height: 600px) {
  .search-overlay {
    padding-top: 2vh;
  }
  
  .search-results {
    max-height: 40vh;
  }
  
  .dialog {
    margin: 10px;
  }
  
  .empty-state {
    padding: 24px;
  }
  
  .empty-state .material-symbols-outlined {
    font-size: 48px;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  .bookmark-actions {
    opacity: 1;
  }
  
  .icon-button {
    width: 44px;
    height: 44px;
  }
  
  .fab {
    width: 56px;
    height: 56px;
  }
  
  .bookmark-item {
    padding: 14px 12px;
  }
  
  .collection-header {
    padding: 16px;
  }
  
  /* Larger tap targets */
  .menu-item {
    padding: 16px;
  }
  
  .search-result-item {
    padding: 16px;
  }
  
  .context-menu-item {
    padding: 12px 16px;
  }
}

/* High DPI screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .bookmark-favicon,
  .search-result-favicon {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .loading-spinner {
    animation: none;
  }
  
  .fade-in,
  .slide-up {
    animation: none;
  }
}

/* Dark theme adjustments for readability */
@media (prefers-color-scheme: dark) {
  .bookmark-favicon,
  .search-result-favicon {
    filter: brightness(0.9);
  }
  
  .collection {
    box-shadow: var(--md-sys-elevation-2);
  }
}

/* Print styles */
@media print {
  .top-app-bar,
  .navigation-drawer,
  .widget-panel,
  .fab,
  .search-overlay,
  .snackbar,
  .dropdown-menu,
  .bookmark-actions,
  .collection-actions {
    display: none !important;
  }
  
  .main-content {
    padding: 0;
  }
  
  .collections-container {
    grid-template-columns: 1fr 1fr;
  }
  
  .collection {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
  }
  
  .bookmark-item {
    page-break-inside: avoid;
  }
  
  body {
    font-size: 12pt;
    line-height: 1.4;
  }
}

/* Accessibility improvements */
@media (prefers-reduced-transparency: reduce) {
  .search-overlay {
    background-color: rgba(0, 0, 0, 0.8);
  }
  
  .dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.6);
  }
}

/* Focus styles for keyboard navigation */
.button:focus-visible,
.icon-button:focus-visible,
.bookmark-item:focus-visible,
.search-result-item:focus-visible,
.menu-item:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* Specific mobile landscape adjustments */
@media (max-width: 1024px) and (orientation: landscape) and (max-height: 600px) {
  .top-app-bar-content {
    height: 56px;
  }
  
  .app-title {
    font: var(--md-sys-typescale-title-small);
  }
  
  .main-content {
    padding: 16px;
  }
  
  .collections-container {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
  }
  
  .search-overlay {
    padding-top: 1vh;
  }
}

/* Container queries for modern browsers */
@supports (container-type: inline-size) {
  .collection {
    container-type: inline-size;
  }
  
  @container (max-width: 280px) {
    .collection-header {
      padding: 8px;
    }
    
    .collection-title {
      font: var(--md-sys-typescale-body-large);
    }
    
    .bookmark-item {
      padding: 8px;
    }
    
    .bookmark-title {
      font: var(--md-sys-typescale-body-small);
    }
  }
}

/* Animation for collection reordering */
.collection.moving {
  opacity: 0.7;
  transform: scale(0.95);
  transition: all var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized);
}

/* Loading states */
.collections-container.loading {
  opacity: 0.6;
  pointer-events: none;
}

.collection.loading {
  position: relative;
  overflow: hidden;
}

.collection.loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* Error states */
.collection.error {
  border: 1px solid var(--md-sys-color-error);
  background-color: var(--md-sys-color-error-container);
}

.bookmark-item.error {
  background-color: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

/* Success states */
.collection.success {
  border: 1px solid var(--md-sys-color-tertiary);
  background-color: var(--md-sys-color-tertiary-container);
}

/* Widget panel responsive behavior */
@media (max-width: 1024px) {
  .widget-panel-toggle {
    display: block;
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    border-radius: 8px 0 0 8px;
    padding: 12px 8px;
    z-index: 100;
    box-shadow: var(--md-sys-elevation-2);
  }
  
  .widget-panel-toggle.hidden {
    right: 320px;
  }
}

@media (min-width: 1025px) {
  .widget-panel-toggle {
    display: none;
  }
}