/**
 * Dashboard Clipping ISAC 2025 - Responsive Styles
 * Mobile-first approach with breakpoints
 */

/* ============================================================================
   Breakpoints
   - sm: 640px (mobile landscape)
   - md: 768px (tablet)
   - lg: 1024px (desktop small)
   - xl: 1280px (desktop medium)
   - 2xl: 1536px (desktop large)
   ========================================================================= */

/* ============================================================================
   Tablet and Below (max-width: 1024px)
   ========================================================================= */

@media (max-width: 1024px) {
  .container {
    padding: 0 var(--space-4);
  }

  .header-app-name {
    font-size: var(--text-lg);
  }

  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .metric-value {
    font-size: var(--text-4xl);
  }

  .card-title {
    font-size: var(--text-lg);
  }
}

/* ============================================================================
   Mobile (max-width: 768px)
   ========================================================================= */

@media (max-width: 768px) {
  :root {
    --text-5xl: 36px;
    --text-4xl: 28px;
    --text-3xl: 24px;
    --text-2xl: 20px;
  }

  .container {
    padding: 0 var(--space-3);
  }

  /* --- Header: compact single row --- */
  .dashboard-header {
    padding: var(--space-2) 0;
  }

  .header-content {
    gap: var(--space-3);
  }

  .header-left {
    gap: var(--space-3);
    min-width: 0;
  }

  .logo {
    height: 50px;
  }

  .header-app-name {
    font-size: 15px;
    line-height: 1.2;
  }

  .header-left > .header-divider {
    display: none;
  }

  .header-actions {
    gap: var(--space-2);
  }

  .header-actions > .header-divider {
    display: none;
  }

  /* Theme toggle: compact on mobile */
  .theme-toggle-track {
    width: 30px;
    height: 16px;
    border-radius: 8px;
  }

  .theme-toggle-thumb {
    width: 10px;
    height: 10px;
    border-radius: 5px;
  }

  .theme-toggle input:checked ~ .theme-toggle-track .theme-toggle-thumb {
    transform: translateX(14px);
  }

  .theme-toggle-sun svg {
    width: 8px;
    height: 8px;
  }

  .theme-toggle-moon svg {
    width: 7px;
    height: 7px;
  }

  .theme-toggle-sun {
    right: 3px;
  }

  .theme-toggle-moon {
    left: 3px;
  }

  .header-right {
    flex-direction: row;
    align-items: center;
    gap: var(--space-2);
  }

  .user-name {
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: var(--text-xs);
  }

  .btn-logout {
    font-size: 11px;
  }

  /* --- Tabs: compact horizontal scroll --- */
  .tabs-navigation {
    padding-top: var(--space-2);
  }

  .tabs-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .tabs-container::-webkit-scrollbar {
    display: none;
  }

  .tab-button .tab-icon {
    display: none;
  }

  /* --- Filters: collapsible on mobile --- */
  .dashboard-filters-section {
    padding: 0;
  }

  .dash-filters-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    gap: var(--space-3);
  }

  .dash-filters-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
  }

  .dash-filters-body.open {
    max-height: 350px;
    transition: max-height 0.4s ease-in;
  }

  .dash-filters-body > .dashboard-filters-container {
    padding: 0 var(--space-4) var(--space-4);
    border-top: 1px solid var(--gray-200);
    padding-top: var(--space-3);
  }

  .dashboard-filters-container {
    flex-direction: column;
    gap: var(--space-3);
  }

  .dashboard-filters-container .filter-group {
    min-width: 0;
    width: 100%;
  }

  .filter-group {
    width: 100%;
    justify-content: space-between;
  }

  .filter-group label {
    flex-shrink: 0;
  }

  .select-primary {
    flex: 1;
    min-width: auto;
  }

  .btn-secondary {
    width: 100%;
    justify-content: center;
  }

  /* --- Main content --- */
  .dashboard-main {
    padding: var(--space-4) 0;
  }

  section {
    margin-bottom: var(--space-6);
  }

  .hero-section {
    padding: var(--space-4);
    margin-bottom: var(--space-6);
  }

  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

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

  .metric-value {
    font-size: var(--text-3xl);
  }

  .metric-icon {
    font-size: var(--text-2xl);
  }

  .sparkline-container {
    height: 30px;
  }

  .card-header,
  .card-body {
    padding: var(--space-4);
  }

  .card-title {
    font-size: var(--text-base);
  }

  .card-subtitle {
    font-size: var(--text-xs);
  }

  .charts-section canvas {
    max-height: 250px;
  }

  .donut-center-text {
    transform: translate(-50%, -50%) scale(0.8);
  }

  .nss-label {
    font-size: var(--text-xs);
  }

  .nss-value {
    font-size: var(--text-3xl);
  }

  .qmentum-grid {
    grid-template-columns: 1fr;
  }

  .qmentum-item {
    padding: var(--space-4);
  }

  .qmentum-value {
    font-size: var(--text-xl);
  }

  .data-table {
    font-size: 11px;
    table-layout: fixed;
    width: 100%;
  }

  .data-table th,
  .data-table td {
    padding: 6px 3px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .data-table thead {
    font-size: 10px;
  }

  .data-table tbody {
    font-size: 8px;
  }

  /* Column widths (5 visible cols = 100%) */
  #unidades-table th:nth-child(1),
  #unidades-table td:nth-child(1) { width: 18%; }
  #unidades-table th:nth-child(2),
  #unidades-table td:nth-child(2) { width: 15%; }
  #unidades-table th:nth-child(3),
  #unidades-table td:nth-child(3) { width: 20%; }
  #unidades-table th:nth-child(5),
  #unidades-table td:nth-child(5) { width: 22%; }
  #unidades-table th:nth-child(6),
  #unidades-table td:nth-child(6) { width: 25%; }

  /* Hide less important columns on mobile */
  .data-table th:nth-child(4),
  .data-table td:nth-child(4) {
    display: none;
  }

  /* Compact sentiment badge on mobile */
  .sentiment-badge {
    padding: 2px 6px;
    font-size: 10px;
    white-space: nowrap;
  }

  .sentiment-badge .sentiment-icon {
    display: none;
  }

  /* Heatmap + Tabela: sigla no mobile */
  .label-full { display: none; }
  .label-short { display: inline; }

  .heatmap-grid {
    grid-template-columns: 80px repeat(var(--hm-months, 12), 1fr);
  }

  .heatmap-label {
    cursor: pointer;
  }

  /* Heatmap: freeze first column (unit labels) */
  .heatmap-header:first-child,
  .heatmap-label {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--white);
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.08);
  }

  .insights-grid {
    gap: var(--space-3);
  }

  .insight-item {
    padding: var(--space-3);
  }

  .insight-item h3 {
    font-size: var(--text-sm);
  }

  .insight-item p {
    font-size: var(--text-xs);
  }

  .month-tabs {
    gap: var(--space-1);
    padding: var(--space-1);
  }

  .month-tab {
    padding: var(--space-1) var(--space-2);
    font-size: var(--text-xs);
  }

  .dashboard-footer {
    padding: var(--space-4) 0;
  }

  .footer-content p {
    font-size: var(--text-xs);
  }
}

/* ============================================================================
   Small Mobile (max-width: 480px)
   ========================================================================= */

@media (max-width: 480px) {
  .logo {
    height: 40px;
  }

  .user-name {
    display: none;
  }

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

  .metric-value {
    font-size: var(--text-2xl);
  }

  .metric-label {
    font-size: var(--text-xs);
  }

  .card-body.chart-center {
    padding: var(--space-3);
  }

  .donut-center-text {
    transform: translate(-50%, -50%) scale(0.6);
  }

  /* Analítico table needs horizontal scroll on very small screens */
  .analitico-container .table-responsive {
    overflow-x: scroll;
  }

  .analitico-table {
    min-width: 500px;
  }

  .stat-box {
    flex-direction: column;
    gap: var(--space-2);
    text-align: center;
  }

  .stat-bar {
    width: 100%;
    margin: var(--space-2) 0;
  }

  .alert {
    padding: var(--space-3);
  }

  .alert-icon {
    font-size: var(--text-base);
  }
}

/* ============================================================================
   Large Desktop (min-width: 1536px)
   ========================================================================= */

@media (min-width: 1536px) {
  .container {
    max-width: 1600px;
  }

  .metric-value {
    font-size: var(--text-6xl);
  }

  .charts-section canvas {
    max-height: 400px;
  }
}

/* ============================================================================
   Landscape Mode (Mobile)
   ========================================================================= */

@media (max-height: 500px) and (orientation: landscape) {
  .dashboard-header {
    padding: var(--space-2) 0;
  }

  .logo {
    height: 30px;
  }

  /* KPIs side by side in landscape */
  .hero-section {
    padding: var(--space-3);
    margin-bottom: var(--space-4);
  }

  .hero-section .grid-3 {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3);
  }

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

  .metric-icon {
    font-size: var(--text-xl);
    margin-bottom: var(--space-1);
  }

  .metric-label {
    font-size: 11px;
    margin-bottom: var(--space-1);
  }

  .metric-value {
    font-size: var(--text-2xl);
    margin-bottom: var(--space-1);
  }

  .metric-trend {
    font-size: 11px;
  }

  .metric-detail {
    font-size: 11px;
  }

  .sparkline-container {
    display: none;
  }
}

/* ============================================================================
   Touch Device Optimizations
   ========================================================================= */

@media (hover: none) and (pointer: coarse) {
  /* Increase touch targets */
  .btn-primary,
  .btn-secondary,
  .btn-ghost {
    min-height: 44px;
    padding: var(--space-3) var(--space-6);
  }

  .select-primary {
    min-height: 44px;
  }

  .month-tab {
    min-height: 40px;
    padding: var(--space-2) var(--space-4);
  }

  /* Remove hover effects on touch */
  .card:hover {
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  }

  .qmentum-item:hover {
    background: var(--gray-50);
    box-shadow: none;
  }

  .data-table tbody tr:hover {
    background: transparent;
  }

  /* Disable tooltips on touch */
  .tooltip-content {
    display: none;
  }
}

/* ============================================================================
   High Contrast Mode
   ========================================================================= */

@media (prefers-contrast: high) {
  :root {
    --gray-200: #D0D0D0;
    --gray-300: #B0B0B0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.3);
  }

  .card,
  .metric-card {
    border-width: 2px;
  }

  .btn-primary,
  .btn-secondary,
  .btn-danger {
    border: 2px solid currentColor;
  }
}

/* ============================================================================
   Reduced Motion
   ========================================================================= */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .spinner {
    animation: none;
    border-top-color: var(--isac-blue-primary);
    border-right-color: var(--isac-blue-primary);
  }
}

/* ============================================================================
   Dark Mode (Optional - for future implementation)
   ========================================================================= */

@media (prefers-color-scheme: dark) {
  /* Can be implemented in future version */
  /* Currently using light mode only */
}
