/**
 * Company Reviews Mobile Optimization
 * Mobile-first responsive design för recensionshantering
 * Fokus: Filter som bottom sheet, kompakta stats, responsiva charts
 */

/* ========== MOBILE LAYOUT ========== */

@media (max-width: 768px) {
  /* Container */
  .reviews-container {
    padding: 1rem !important;
    padding-top: 80px !important;
    padding-bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    max-width: 100% !important;
  }

  /* ========== HEADER ========== */
  .reviews-header {
    min-height: 15.5rem !important;
    padding: 1.25rem 1.1rem 1.15rem !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.75rem !important;
    margin-bottom: 1rem !important;
  }

  .reviews-header::before {
    background-size: cover !important;
    background-position: 75% 68% !important;
    opacity: 0.55;
  }

  .reviews-header::after {
    background: linear-gradient(
      180deg,
      rgba(22, 35, 30, 0.88) 0%,
      rgba(22, 35, 30, 0.72) 55%,
      rgba(22, 35, 30, 0.55) 100%
    ) !important;
  }

  .reviews-header-left {
    max-width: 100% !important;
  }

  .reviews-header-left h1 {
    font-size: 1.5rem !important;
  }

  .reviews-header-left p {
    font-size: 0.875rem !important;
  }

  /* ========== TAB NAVIGATION - STICKY & SCROLLABLE ========== */
  .reviews-tabs {
    position: sticky !important;
    top: 80px !important;
    margin: 0 -1rem 1.5rem -1rem !important;
    padding: 0.5rem 1rem !important;
    overflow-x: auto !important;
    scroll-behavior: smooth !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    z-index: 100 !important;
    background: var(--arv-offwhite-card, #FBFaf7) !important;
    box-shadow: 0 2px 8px rgba(15, 17, 18, 0.05) !important;
  }

  .reviews-tabs::-webkit-scrollbar {
    display: none !important;
  }

  .tabs-nav {
    gap: 0.5rem !important;
    min-width: min-content !important;
  }

  .tab-button {
    padding: 0.625rem 1rem !important;
    font-size: 0.875rem !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
  }

  .tab-button .badge {
    padding: 0.125rem 0.375rem !important;
    font-size: 0.688rem !important;
    margin-left: 0.375rem !important;
  }

  /* ========== HERO RATING - KOMPAKT ========== */
  .hero-rating {
    padding: 1.5rem 1rem !important;
    text-align: center !important;
    margin-bottom: 1.5rem !important;
  }

  .hero-rating-value {
    font-size: 3rem !important;
    line-height: 1 !important;
  }

  .overview-section {
    padding: 1.1rem !important;
  }

  .overview-section-header {
    margin-bottom: 0.75rem !important;
  }

  .overview-quick-actions {
    gap: 0.45rem !important;
  }

  .overview-action-chip {
    flex: 1 1 auto;
    justify-content: center;
  }

  .overview-recent .recent-review-row {
    padding: 0.9rem 0 !important;
  }

  .empty-state .btn {
    margin-top: 1rem;
  }

  .hero-rating-stars {
    margin: 0.5rem 0 !important;
  }

  .hero-rating-label {
    font-size: 0.875rem !important;
  }

  /* ========== STATS GRID - 2x2 ========== */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.75rem !important;
    margin-bottom: 1.5rem !important;
  }

  .stat-card {
    padding: 1rem !important;
  }

  .stat-icon {
    width: 40px !important;
    height: 40px !important;
    font-size: 1.25rem !important;
  }

  .stat-value {
    font-size: 1.5rem !important;
    margin: 0.5rem 0 0.25rem !important;
  }

  .stat-label {
    font-size: 0.75rem !important;
  }

  /* ========== REVIEW CARDS ========== */
  .review-card {
    padding: 1rem !important;
    margin-bottom: 1rem !important;
    border-radius: 1rem !important;
  }

  .review-card h3 {
    font-size: 1.125rem !important;
    margin-bottom: 1rem !important;
  }

  /* ========== QUICK ACTIONS ========== */
  .review-actions {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
  }

  .review-actions .btn {
    width: 100% !important;
    justify-content: center !important;
    padding: 0.875rem !important;
    font-size: 0.938rem !important;
  }

  /* ========== RECENT REVIEWS LIST ========== */
  #recentReviewsList {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.75rem !important;
  }

  .review-item {
    padding: 1rem !important;
    border-radius: 0.75rem !important;
  }

  .review-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.5rem !important;
  }

  .review-rating {
    margin-bottom: 0.5rem !important;
  }

  .review-text {
    font-size: 0.875rem !important;
    line-height: 1.5 !important;
  }

  .review-actions-inline {
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
    margin-top: 0.75rem !important;
  }

  .review-actions-inline .btn {
    padding: 0.5rem 0.875rem !important;
    font-size: 0.813rem !important;
  }

  /* ========== SHOWCASE TAB ========== */

  /* Filters row */
  #tab-showcase > .review-card:first-child {
    padding: 0.875rem !important;
  }

  #tab-showcase > .review-card:first-child > div {
    flex-direction: column !important;
    gap: 0.75rem !important;
  }

  #showcaseOnlyPositive {
    width: 18px !important;
    height: 18px !important;
  }

  #showcaseSort {
    width: 100% !important;
    padding: 0.75rem !important;
    font-size: 0.938rem !important;
  }

  /* Showcase Grid */
  .showcase-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  .showcase-item {
    padding: 1rem !important;
  }

  /* ========== HANTERA TAB - MOBILE LAYOUT ========== */
  #tab-manage > div {
    display: block !important; /* Single column instead of grid */
  }

  /* ========== FILTER SIDEBAR -> BOTTOM SHEET ========== */
  .filter-sidebar {
    display: block !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    margin: 0;
    max-height: min(80vh, 640px);
    overflow-y: auto;
    border-radius: 24px 24px 0 0;
    z-index: 1002;
    transform: translateY(110%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -8px 28px rgba(15, 17, 18, 0.18);
    background: var(--bg-card, #FBFaf7);
    border: 1px solid var(--border-color, rgba(199, 204, 209, 0.65));
    border-bottom: none;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
  }

  .filter-sidebar.is-open {
    transform: translateY(0);
  }

  .filter-sheet-handle {
    display: block;
    width: 40px;
    height: 4px;
    background: #cbd5e1;
    border-radius: 2px;
    margin: 0 auto 1rem;
  }

  /* Mobile filter button */
  .mobile-filter-btn {
    position: sticky;
    top: calc(140px + env(safe-area-inset-top));
    padding: 0.875rem;
    background: var(--bg-card, #FBFaf7);
    border: 1px solid var(--border-color, rgba(199, 204, 209, 0.65));
    border-radius: 0.75rem;
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    z-index: 50;
    box-shadow: 0 2px 8px rgba(15, 17, 18, 0.06);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
    color: var(--text-primary, #0F1112);
  }

  .mobile-filter-btn:active {
    transform: scale(0.98);
    background: var(--bg-hover, #EAE6DF);
  }

  .mobile-filter-btn i {
    font-size: 1.125rem;
  }

  /* Filter Bottom Sheet overlay */
  .filter-sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 17, 18, 0.45);
    z-index: 1001;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .filter-sidebar-overlay.is-open {
    display: block;
    opacity: 1;
  }

  .filter-bottom-sheet-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1001;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .filter-bottom-sheet-overlay.active {
    display: block;
    opacity: 1;
  }

  .filter-bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 24px 24px 0 0;
    padding: 1.5rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1002;
    max-height: 80vh;
    overflow-y: auto;
  }

  .filter-bottom-sheet-overlay.active .filter-bottom-sheet {
    transform: translateY(0);
  }

  body.filter-sheet-open {
    overflow: hidden;
  }

  .filter-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e2e8f0;
  }

  .filter-sheet-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1e293b;
  }

  .filter-sheet-close {
    width: 32px;
    height: 32px;
    border: none;
    background: #f1f5f9;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #64748b;
  }

  .filter-sheet-close:active {
    transform: scale(0.9);
    background: #e2e8f0;
  }

  .filter-section {
    margin-bottom: 1.5rem !important;
  }

  .filter-section-title {
    font-size: 1rem !important;
    font-weight: 600 !important;
    margin-bottom: 0.75rem !important;
  }

  .filter-checkbox {
    padding: 0.75rem !important;
    margin-bottom: 0.5rem !important;
  }

  .filter-checkbox input {
    width: 20px !important;
    height: 20px !important;
  }

  .filter-checkbox label {
    font-size: 0.938rem !important;
  }

  #filterDate {
    width: 100% !important;
    padding: 0.75rem !important;
    font-size: 0.938rem !important;
  }

  .filter-sheet-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
  }

  .filter-sheet-actions .btn {
    flex: 1;
    padding: 0.875rem !important;
    font-size: 0.938rem !important;
  }

  /* ========== MANAGE REVIEWS LIST ========== */
  #manageReviewsList {
    display: flex !important;
    flex-direction: column !important;
    gap: 1rem !important;
  }

  /* ========== ANALYTICS TAB ========== */

  /* Period selector */
  #tab-analytics > .review-card:first-child {
    padding: 0.875rem !important;
  }

  #tab-analytics > .review-card:first-child > div {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.75rem !important;
  }

  #analyticsPeriod {
    width: 100% !important;
    padding: 0.75rem !important;
    font-size: 0.938rem !important;
  }

  /* Charts - Stack vertically */
  .chart-container {
    margin-bottom: 1.5rem !important;
    padding: 1rem !important;
    height: auto !important;
  }

  .chart-title {
    font-size: 1rem !important;
    margin-bottom: 1rem !important;
  }

  .chart-container canvas {
    max-height: 250px !important;
    width: 100% !important;
  }

  .chart-surface--trend {
    height: 200px !important;
  }

  .chart-empty--trend {
    padding: 1rem 0.5rem !important;
  }

  #tab-analytics > div[style*="grid"],
  #tab-analytics .analytics-charts-grid {
    display: block !important;
  }

  #tab-analytics > div[style*="grid"] > .chart-container,
  #tab-analytics .analytics-charts-grid > .chart-container {
    margin-bottom: 1rem !important;
  }

  .chart-surface--bar {
    height: 220px !important;
  }

  /* ========== SETTINGS TAB ========== */

  /* Notification settings */
  label[style*="cursor: pointer"] {
    padding: 1rem !important;
    gap: 0.75rem !important;
  }

  label input[type="checkbox"] {
    width: 20px !important;
    height: 20px !important;
    flex-shrink: 0 !important;
  }

  /* Templates list */
  #templatesList {
    max-height: 300px !important;
    overflow-y: auto !important;
  }

  .template-item {
    padding: 0.875rem !important;
    margin-bottom: 0.5rem !important;
    font-size: 0.875rem !important;
  }

  #addTemplateBtn,
  #saveSettingsBtn {
    width: 100% !important;
    padding: 0.875rem 1.5rem !important;
    font-size: 1rem !important;
  }

  /* ========== REPLY MODAL ========== */
  .modal-overlay {
    padding: 1rem !important;
  }

  .modal-content {
    max-width: 100% !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
    margin: auto !important;
  }

  .modal-header {
    padding: 1rem !important;
  }

  .modal-title {
    font-size: 1.125rem !important;
  }

  .modal-close {
    width: 32px !important;
    height: 32px !important;
  }

  .modal-body {
    padding: 1rem !important;
  }

  #replyModalReview {
    padding: 1rem !important;
    margin-bottom: 1rem !important;
  }

  .form-textarea {
    min-height: 120px !important;
    font-size: 16px !important; /* Prevent iOS zoom */
  }

  #replyTemplate {
    width: 100% !important;
    padding: 0.625rem !important;
    font-size: 0.875rem !important;
    margin-bottom: 0.5rem !important;
  }

  #aiSuggestBtn {
    width: 100% !important;
    padding: 0.625rem !important;
    font-size: 0.875rem !important;
  }

  .char-counter {
    font-size: 0.813rem !important;
    margin-top: 0.5rem !important;
  }

  .modal-footer {
    padding: 1rem !important;
    gap: 0.5rem !important;
    flex-direction: column-reverse !important;
  }

  .modal-footer .btn {
    width: 100% !important;
    padding: 0.875rem !important;
    font-size: 1rem !important;
  }

  /* ========== CONFIRM MODAL ========== */
  #confirmModal .modal-content {
    max-width: 90% !important;
    padding: 1.5rem !important;
  }

  #confirmMessage {
    font-size: 0.938rem !important;
    line-height: 1.5 !important;
  }
}

/* ========== SMALL SCREENS (< 360px) ========== */
@media (max-width: 360px) {
  .reviews-container {
    padding: 0.75rem !important;
  }

  .reviews-header {
    padding: 0.75rem !important;
  }

  .reviews-header-left h1 {
    font-size: 1.25rem !important;
  }

  .hero-rating-value {
    font-size: 2.5rem !important;
  }

  .stats-grid {
    gap: 0.5rem !important;
  }

  .stat-card {
    padding: 0.75rem !important;
  }

  .review-card {
    padding: 0.875rem !important;
  }

  .tab-button {
    padding: 0.5rem 0.875rem !important;
    font-size: 0.813rem !important;
  }

  .mobile-filter-btn {
    padding: 0.75rem !important;
    font-size: 0.875rem !important;
  }
}

/* ========== LANDSCAPE MODE ========== */
@media (max-width: 768px) and (orientation: landscape) {
  .reviews-tabs {
    top: 60px !important;
  }

  .reviews-container {
    padding-top: 70px !important;
  }

  .hero-rating {
    padding: 1rem !important;
  }

  .hero-rating-value {
    font-size: 2.5rem !important;
  }

  .stats-grid {
    grid-template-columns: repeat(4, 1fr) !important;
  }

  .chart-container canvas {
    max-height: 200px !important;
  }
}

/* ========== TOUCH OPTIMIZATIONS ========== */
@media (max-width: 768px) {
  /* Större touch targets */
  .tab-button,
  .btn,
  .review-actions-inline .btn,
  .mobile-filter-btn,
  .filter-checkbox,
  input[type="checkbox"],
  select {
    min-height: 44px !important;
  }

  /* Tap highlight */
  * {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.05) !important;
  }

  /* Prevent double-tap zoom */
  button,
  .btn {
    touch-action: manipulation !important;
  }

  /* Smooth scrolling */
  html {
    scroll-behavior: smooth !important;
  }

  /* Momentum scrolling */
  .reviews-tabs,
  .filter-bottom-sheet,
  #templatesList,
  .meetings-list {
    -webkit-overflow-scrolling: touch !important;
  }
}

/* ========== ANIMATIONS ========== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tab-content.active {
  animation: fadeInUp 0.3s ease !important;
}

/* Review item entrance animation */
.review-item {
  animation: fadeInUp 0.3s ease !important;
}

/* ========== ACCESSIBILITY ========== */
@media (max-width: 768px) {
  /* Focus states */
  *:focus-visible {
    outline: 3px solid #0ea5e9 !important;
    outline-offset: 2px !important;
  }

  /* Skip to content */
  .skip-to-reviews {
    position: absolute;
    top: -100px;
    left: 0;
    background: #0f172a;
    color: white;
    padding: 1rem;
    z-index: 9999;
  }

  .skip-to-reviews:focus {
    top: 0;
  }
}

/* ========== PRINT MEDIA ========== */
@media print {
  .reviews-tabs,
  .mobile-filter-btn,
  .filter-bottom-sheet-overlay,
  .company-mobile-bottom-nav,
  .btn,
  .modal-overlay {
    display: none !important;
  }

  .reviews-container {
    padding: 0 !important;
  }

  .tab-content {
    display: block !important;
  }
}
