/* ========================================
   Responsive Design - Complete Overhaul
   ======================================== */

/* Sidebar Toggle Button - Hidden by default */
.detail-sidebar-toggle {
  display: none;
  position: fixed;
  top: var(--space-md);
  left: var(--space-md);
  z-index: 90;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.detail-sidebar-toggle:hover {
  background: var(--surface-hover);
  box-shadow: var(--shadow-hover);
}

/* Sidebar Overlay */
.detail-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(16, 42, 67, 0.5);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.detail-sidebar-overlay.open {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

/* Small Desktop / Large Tablet */
@media (max-width: 1280px) {
  .app-layout,
  .detail-layout,
  .admin-layout,
  .hero-app,
  .hero-admin,
  .hero-detail {
    grid-template-columns: 1fr;
  }

  .sidebar-stack,
  .detail-side,
  .admin-side {
    position: static;
    max-height: none;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-layout {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .shell-detail-shell .detail-sidebar {
    min-width: 220px;
    max-width: 220px;
  }

  .chat-input-wrapper,
  .bubble-content {
    max-width: 680px;
  }
}

/* Tablet */
@media (max-width: 1024px) {
  :root {
    --space-xl: 28px;
    --space-lg: 20px;
  }

  .shell {
    width: min(1400px, calc(100% - 40px));
  }

  .detail-layout {
    grid-template-columns: 200px minmax(0, 1fr);
  }

  .shell-detail-shell .detail-sidebar {
    min-width: 200px;
    max-width: 200px;
  }

  .task-list-sidebar .day-title {
    font-size: 0.78rem;
  }

  .task-list-sidebar .command-text {
    font-size: 0.68rem;
  }

  .chat-input-wrapper,
  .bubble-content {
    max-width: 600px;
  }
}

/* Large Phone / Small Tablet */
@media (max-width: 768px) {
  :root {
    --space-xl: 24px;
    --space-lg: 18px;
    --space-md: 14px;
    --space-sm: 10px;
  }

  .shell:not(.shell-detail-shell) {
    width: calc(100% - 32px);
    margin: var(--space-lg) auto var(--space-xl);
  }

  /* User menu mobile */
  .user-menu {
    top: var(--space-sm);
    right: var(--space-sm);
  }

  .user-menu-trigger {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.8rem;
  }

  .user-menu-name {
    max-width: 80px;
  }

  .user-menu-dropdown {
    width: 240px;
    right: 0;
  }

  .hero {
    padding: var(--space-lg);
    border-radius: var(--radius-xl);
  }

  .hero strong {
    max-width: none;
    font-size: 1.75rem;
    white-space: normal;
  }

  .hero h1 {
    font-size: 1.5rem;
  }

  .panel {
    padding: var(--space-md);
    border-radius: var(--radius);
  }

  .modal-overlay {
    padding: var(--space-md);
    align-items: flex-end;
  }

  .modal-content {
    width: 100%;
    max-height: 85vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  }

  .metric-grid,
  .cards-grid,
  .field-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .card-head,
  .card footer,
  .section-heading,
  .panel-heading,
  .block-heading {
    flex-direction: column;
    align-items: flex-start;
  }

  .import-actions {
    flex-direction: column;
  }

  .import-actions button {
    width: 100%;
  }

  /* Detail full screen */
  .detail-layout {
    grid-template-columns: 1fr;
  }

  .shell-detail-shell .detail-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(280px, 85%);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: var(--shadow-lg);
    min-width: unset;
    max-width: unset;
  }

  .shell-detail-shell .detail-sidebar.open {
    transform: translateX(0);
  }

  /* Chat full width */
  .chat-input-wrapper,
  .bubble-content {
    max-width: 100%;
    margin: 0 var(--space-xs);
  }

  .chat-input-wrapper {
    border-radius: 12px;
  }

  .chat-bubble.user .bubble-body {
    max-width: 90%;
    padding: 8px 12px;
    font-size: 0.9rem;
  }

  .bubble-body {
    font-size: 0.9rem;
  }

  .chat-suggestions {
    flex-direction: column;
    align-items: center;
  }

  .suggestion-btn {
    width: 100%;
    max-width: 280px;
  }

  textarea,
  .import-form textarea,
  .plan-form textarea {
    min-height: 150px;
  }

  .chat-main .chat-log {
    max-height: none;
  }
}

/* Small Phone */
@media (max-width: 480px) {
  .shell:not(.shell-detail-shell) {
    width: calc(100% - 24px);
    margin: var(--space-md) auto;
  }

  .hero-badges {
    gap: var(--space-xs);
  }

  .hero-badges span {
    font-size: 0.72rem;
    padding: 6px 10px;
  }

  button {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.82rem;
  }

  .brand svg {
    width: 44px;
    height: 44px;
  }

  .hero strong {
    font-size: 1.5rem;
    white-space: normal;
  }

  .hero h1 {
    font-size: 1.3rem;
  }

  .card {
    padding: var(--space-md);
  }

  .card h3 {
    font-size: 0.9rem;
  }

  .task-list-sidebar .day-header {
    padding: 8px 10px;
  }

  .task-list-sidebar .day-number {
    font-size: 0.6rem;
    padding: 2px 5px;
  }

  .task-list-sidebar .day-title {
    font-size: 0.75rem;
  }

  .task-list-sidebar .command-text {
    font-size: 0.65rem;
  }

  .task-list-sidebar .command-desc {
    font-size: 0.62rem;
  }

  .task-list-sidebar .command-actions .ghost-button {
    padding: 2px 6px;
    font-size: 0.58rem;
  }

  .chat-input-wrapper {
    padding: var(--space-xs);
  }

  .chat-input-wrapper textarea {
    font-size: 0.88rem;
    padding: 4px 6px;
  }

  .chat-input-actions button {
    width: 30px;
    height: 30px;
  }

  .chat-input-actions button svg {
    width: 14px;
    height: 14px;
  }

  .bubble-content {
    padding: var(--space-sm) var(--space-sm);
  }

  .bubble-body {
    font-size: 0.85rem;
  }

  .bubble-body code {
    font-size: 0.82em;
  }

  .suggestion-btn {
    font-size: 0.78rem;
    padding: var(--space-xs) var(--space-sm);
  }

  .modal-content {
    padding: var(--space-md);
  }

  .modal-header h2 {
    font-size: 1.1rem;
  }

  /* Quiz responsive */
  .quiz-option-btn {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.82rem;
  }

  .quiz-question-text {
    font-size: 0.88rem;
  }

  .quiz-score {
    font-size: 1rem;
  }
}

/* Ultra Small Phone */
@media (max-width: 360px) {
  .shell:not(.shell-detail-shell) {
    width: calc(100% - 20px);
  }

  .hero {
    padding: var(--space-md);
  }

  .hero strong {
    font-size: 1.35rem;
    white-space: normal;
  }

  .panel {
    padding: var(--space-sm);
  }

  .metric-card {
    padding: var(--space-md);
  }

  .metric-card strong {
    font-size: 1.5rem;
  }

  .card {
    padding: var(--space-sm);
    gap: var(--space-sm);
  }

  .card h3 {
    font-size: 0.85rem;
  }

  .bubble-body {
    font-size: 0.82rem;
  }

  .chat-bubble.user .bubble-body {
    padding: 6px 10px;
  }
}

/* Landscape phones */
@media (max-height: 600px) and (orientation: landscape) {
  .hero {
    padding: var(--space-md);
  }

  .hero strong {
    font-size: 1.5rem;
    white-space: normal;
  }

  .modal-overlay {
    align-items: flex-start;
  }

  .modal-content {
    max-height: 90vh;
    overflow-y: auto;
  }

  .chat-main .chat-log {
    min-height: 200px;
  }

  textarea {
    min-height: 80px;
  }
}

/* Large screens */
@media (min-width: 1920px) {
  :root {
    --space-xl: 40px;
    --space-lg: 28px;
    --space-md: 18px;
  }

  .shell {
    width: min(1600px, calc(100% - 64px));
  }

  .hero strong {
    font-size: clamp(2rem, 3vw, 3rem);
  }

  .cards-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .chat-input-wrapper,
  .bubble-content {
    max-width: 800px;
  }
}

/* Ultra-wide screens */
@media (min-width: 2560px) {
  .shell {
    width: min(2000px, calc(100% - 80px));
  }

  .hero strong {
    font-size: clamp(2.5rem, 3.5vw, 4rem);
  }

  .cards-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .chat-input-wrapper,
  .bubble-content {
    max-width: 900px;
  }

  .bubble-body {
    font-size: 1.05rem;
  }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .shell {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

/* Print styles */
@media print {
  .shell {
    width: 100%;
    margin: 0;
  }

  .hero {
    box-shadow: none;
    border: 1px solid #ccc;
  }

  .panel {
    box-shadow: none;
    break-inside: avoid;
  }

  button,
  .import-actions,
  .chat-form {
    display: none !important;
  }
}
