/* ===== RESPONSIVE CSS ===== */

/* ===== LARGE DESKTOPS (1440px+) ===== */
@media (min-width: 1440px) {
  .app-container {
    max-width: 900px;
  }
  
  .main-content {
    padding: 3rem;
    gap: 2.5rem;
  }
  
  .app-header {
    padding: 2rem 3rem;
  }
  
  .app-title {
    font-size: 2rem;
  }
  
  .controls-section {
    gap: 2rem;
  }
  
  .todo-item {
    padding: 1.25rem;
  }
}

/* ===== DESKTOPS (1024px - 1439px) ===== */
@media (max-width: 1439px) and (min-width: 1024px) {
  .app-container {
    max-width: 750px;
  }
  
  .main-content {
    padding: 2.5rem;
    gap: 2rem;
  }
  
  .controls-section {
    gap: 1.5rem;
  }
}

/* ===== TABLETS LANDSCAPE (768px - 1023px) ===== */
@media (max-width: 1023px) and (min-width: 768px) {
  .app-container {
    max-width: 700px;
    margin: 0 1rem;
  }
  
  .main-content {
    padding: 2rem 1.5rem;
    gap: 1.75rem;
  }
  
  .app-header {
    padding: 1.5rem 1.5rem;
  }
  
  .header-content {
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
  }
  
  .connection-status {
    align-self: center;
  }
  
  .filters {
    justify-content: center;
  }
  
  .actions {
    justify-content: center;
  }
  
  .footer-content {
    flex-direction: column;
    text-align: center;
  }
}

/* ===== TABLETS PORTRAIT (481px - 767px) ===== */
@media (max-width: 767px) and (min-width: 481px) {
  .app-container {
    margin: 0 0.5rem;
  }
  
  .main-content {
    padding: 1.5rem 1rem;
    gap: 1.5rem;
  }
  
  .app-header {
    padding: 1.25rem 1rem;
  }
  
  .app-title {
    font-size: 1.5rem;
  }
  
  .header-content {
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
  }
  
  .connection-status {
    align-self: center;
  }
  
  .input-group {
    flex-direction: column;
    gap: 0.75rem;
  }
  
  .add-btn {
    width: 100%;
    justify-content: center;
  }
  
  .add-btn i {
    display: inline-block;
  }
  
  .add-btn .btn-text {
    display: none;
  }
  
  .filters {
    justify-content: center;
    gap: 0.375rem;
  }
  
  .filter-btn {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
  }
  
  .filter-btn i {
    display: none;
  }
  
  .actions {
    justify-content: center;
    gap: 0.375rem;
  }
  
  .action-btn {
    padding: 0.5rem 0.625rem;
    font-size: 0.8rem;
  }
  
  .action-btn i {
    margin: 0;
  }
  
  .action-btn .btn-text {
    display: none;
  }
  
  .todo-item {
    padding: 0.875rem;
    gap: 0.625rem;
  }
  
  .todo-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  
  .footer-content {
    flex-direction: column;
    text-align: center;
    gap: 0.75rem;
  }
}

/* ===== MOBILE DEVICES (320px - 480px) ===== */
@media (max-width: 480px) and (min-width: 320px) {
  .app-container {
    margin: 0;
    min-height: 100vh;
  }
  
  .main-content {
    padding: 1rem 0.75rem;
    gap: 1.25rem;
  }
  
  .app-header {
    padding: 1rem 0.75rem;
  }
  
  .app-title {
    font-size: 1.25rem;
    gap: 0.5rem;
  }
  
  .header-content {
    flex-direction: column;
    gap: 0.75rem;
    align-items: stretch;
  }
  
  .connection-status {
    align-self: center;
    font-size: 0.75rem;
    padding: 0.375rem 0.5rem;
  }
  
  .input-group {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .todo-input {
    padding: 0.75rem;
    font-size: 0.95rem;
  }
  
  .add-btn {
    width: 100%;
    padding: 0.75rem;
    justify-content: center;
  }
  
  .add-btn i {
    display: inline-block;
  }
  
  .add-btn .btn-text {
    display: none;
  }
  
  .controls-section {
    gap: 1.25rem;
  }
  
  .filters {
    flex-wrap: wrap;
    gap: 0.25rem;
    justify-content: center;
  }
  
  .filter-btn {
    padding: 0.5rem;
    font-size: 0.75rem;
    flex: 1;
    min-width: 80px;
  }
  
  .filter-btn i {
    display: none;
  }
  
  .filter-btn .count {
    font-size: 0.65rem;
    padding: 0.1rem 0.25rem;
  }
  
  .actions {
    flex-wrap: wrap;
    gap: 0.25rem;
    justify-content: center;
  }
  
  .action-btn {
    padding: 0.5rem;
    font-size: 0.75rem;
    flex: 1;
    min-width: 70px;
  }
  
  .action-btn i {
    margin: 0;
    font-size: 0.9rem;
  }
  
  .action-btn .btn-text {
    display: none;
  }
  
  .todo-list {
    gap: 0.5rem;
  }
  
  .todo-item {
    padding: 0.75rem;
    gap: 0.5rem;
    border-radius: var(--border-radius);
  }
  
  .todo-checkbox {
    width: 1.1rem;
    height: 1.1rem;
  }
  
  .todo-text {
    font-size: 0.95rem;
  }
  
  .todo-meta {
    font-size: 0.7rem;
  }
  
  .todo-actions {
    opacity: 1;
    gap: 0.125rem;
  }
  
  .todo-action {
    padding: 0.25rem;
  }
  
  .empty-state {
    padding: 2rem 1rem;
  }
  
  .empty-state i {
    font-size: 2.5rem;
  }
  
  .empty-state h3 {
    font-size: 1.1rem;
  }
  
  .empty-state p {
    font-size: 0.9rem;
  }
  
  .app-footer {
    padding: 1rem 0.75rem;
  }
  
  .footer-text {
    font-size: 0.8rem;
  }
  
  .last-sync {
    font-size: 0.7rem;
  }
  
  .toast-container {
    left: 0.5rem;
    right: 0.5rem;
    top: 0.5rem;
  }
  
  .toast {
    padding: 0.75rem;
    font-size: 0.85rem;
  }
  
  .modal-content {
    width: 95%;
    margin: 1rem;
  }
  
  .modal-header {
    padding: 1rem;
  }
  
  .modal-body {
    padding: 1rem;
  }
  
  .install-prompt {
    left: 0.5rem;
    right: 0.5rem;
    bottom: 0.5rem;
  }
  
  .install-content {
    flex-direction: column;
    text-align: center;
    gap: 0.75rem;
  }
  
  .install-actions {
    flex-direction: column;
    width: 100%;
  }
  
  .install-btn,
  .dismiss-btn {
    width: 100%;
  }
}

/* ===== VERY SMALL MOBILE DEVICES (below 320px) ===== */
@media (max-width: 319px) {
  .app-container {
    margin: 0;
  }
  
  .main-content {
    padding: 0.75rem 0.5rem;
    gap: 1rem;
  }
  
  .app-header {
    padding: 0.75rem 0.5rem;
  }
  
  .app-title {
    font-size: 1.1rem;
  }
  
  .connection-status {
    font-size: 0.7rem;
    padding: 0.25rem 0.375rem;
  }
  
  .todo-input {
    padding: 0.625rem;
    font-size: 0.9rem;
  }
  
  .add-btn {
    padding: 0.625rem;
  }
  
  .filters {
    gap: 0.125rem;
  }
  
  .filter-btn {
    padding: 0.375rem;
    font-size: 0.7rem;
  }
  
  .actions {
    gap: 0.125rem;
  }
  
  .action-btn {
    padding: 0.375rem;
    font-size: 0.7rem;
  }
  
  .todo-item {
    padding: 0.5rem;
    gap: 0.375rem;
  }
  
  .todo-text {
    font-size: 0.9rem;
  }
  
  .todo-meta {
    font-size: 0.65rem;
  }
  
  .todo-action {
    padding: 0.125rem;
  }
  
  .empty-state {
    padding: 1.5rem 0.5rem;
  }
  
  .empty-state i {
    font-size: 2rem;
  }
  
  .empty-state h3 {
    font-size: 1rem;
  }
  
  .empty-state p {
    font-size: 0.85rem;
  }
  
  .app-footer {
    padding: 0.75rem 0.5rem;
  }
  
  .footer-text {
    font-size: 0.75rem;
  }
  
  .last-sync {
    font-size: 0.65rem;
  }
}

/* ===== LANDSCAPE ORIENTATION FIXES ===== */
@media (orientation: landscape) and (max-height: 500px) {
  .app-header {
    padding: 0.75rem 1rem;
  }
  
  .main-content {
    padding: 1rem;
    gap: 1rem;
  }
  
  .app-title {
    font-size: 1.25rem;
  }
  
  .app-footer {
    padding: 0.75rem 1rem;
  }
  
  .install-prompt {
    bottom: 0.25rem;
  }
}

/* ===== HIGH DPI DISPLAYS ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .todo-checkbox {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* ===== TOUCH DEVICE OPTIMIZATIONS ===== */
@media (hover: none) and (pointer: coarse) {
  .todo-item:hover {
    transform: none;
    box-shadow: none;
  }
  
  .todo-actions {
    opacity: 1;
  }
  
  .filter-btn:hover,
  .action-btn:hover,
  .add-btn:hover {
    transform: none;
  }
  
  .todo-action,
  .filter-btn,
  .action-btn,
  .add-btn,
  .close-btn,
  .todo-action,
  .toast-close {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .hover-lift:hover,
  .hover-scale:hover,
  .hover-rotate:hover,
  .hover-glow:hover {
    transform: none;
  }
  
  .loading-spinner {
    animation: none;
    border: 3px solid var(--primary-color);
  }
}

/* ===== HIGH CONTRAST MODE ===== */
@media (prefers-contrast: high) {
  :root {
    --border-color: #000000;
    --border-light: #333333;
    --text-light: #555555;
  }
  
  .todo-item {
    border-width: 2px;
  }
  
  .filter-btn,
  .action-btn,
  .add-btn {
    border-width: 2px;
  }
}

/* ===== PRINT STYLES ===== */
@media print {
  .app-header,
  .controls-section,
  .app-footer,
  .install-prompt,
  .toast-container {
    display: none !important;
  }
  
  .app-container {
    box-shadow: none;
    max-width: none;
    margin: 0;
  }
  
  .main-content {
    padding: 0;
  }
  
  .todo-item {
    break-inside: avoid;
    border: 1px solid #000;
    margin-bottom: 0.5rem;
  }
  
  .todo-checkbox {
    transform: scale(1.2);
  }
  
  .todo-text {
    font-size: 12pt;
  }
  
  .todo-meta {
    font-size: 9pt;
    color: #333;
  }
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */
@media (prefers-contrast: high) {
  .connection-indicator {
    border: 1px solid currentColor;
  }
  
  .filter-btn.active {
    border: 3px solid;
  }
}

/* Focus improvements for better accessibility */
@media (max-width: 767px) {
  *:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
  }
  
  .filter-btn:focus-visible,
  .action-btn:focus-visible,
  .add-btn:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
  }
}

/* ===== SAFE AREA SUPPORT (iOS) ===== */
@supports (padding: max(0px)) {
  .app-container {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  
  .main-content {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  
  .app-header {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  
  .app-footer {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

/* ===== RESPONSIVE FONT SIZES ===== */
@media (max-width: 480px) {
  html {
    font-size: 14px;
  }
}

@media (max-width: 320px) {
  html {
    font-size: 13px;
  }
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

@media (min-width: 1440px) {
  html {
    font-size: 17px;
  }
}

/* ===== DARK MODE RESPONSIVE ===== */
@media (prefers-color-scheme: dark) and (max-width: 767px) {
  .connection-indicator.offline {
    background-color: #f59e0b;
  }
  
  .connection-indicator.online {
    background-color: #34d399;
  }
}

/* ===== UTILITY CLASSES FOR RESPONSIVE BEHAVIOR ===== */
.mobile-only {
  display: none;
}

@media (max-width: 767px) {
  .mobile-only {
    display: block;
  }
  
  .desktop-only {
    display: none;
  }
}

@media (min-width: 768px) {
  .mobile-only {
    display: none;
  }
  
  .desktop-only {
    display: block;
  }
}

.tablet-only {
  display: none;
}

@media (min-width: 481px) and (max-width: 767px) {
  .tablet-only {
    display: block;
  }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */
.todo-list {
  contain: layout style paint;
}

.todo-item {
  contain: layout style;
}

.will-change-transform {
  will-change: transform;
}

.will-change-opacity {
  will-change: opacity;
}

/* ===== LOADING STATES ===== */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

@media (prefers-color-scheme: dark) {
  .skeleton {
    background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
    background-size: 200% 100%;
  }
}