/* Tablet and below - 1024px */
@media (max-width: 1024px) {
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .project-layout {
    grid-template-columns: 1fr;
  }

  .doc-info {
    grid-template-columns: 1fr;
  }

  .doc-footer {
    grid-template-columns: 1fr;
    gap: var(--spacing-lg);
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}

/* Mobile - 768px */
@media (max-width: 768px) {
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    z-index: 1000;
    transition: left 0.3s ease;
  }

  .sidebar.open {
    left: 0;
  }

  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: none;
  }

  .sidebar-overlay.show {
    display: block;
  }

  .main-content {
    width: 100%;
    overflow-x: hidden;
    max-width: 100%;
  }

  .topbar {
    padding: var(--spacing-sm) var(--spacing-md);
    gap: var(--spacing-sm);
  }

  .content-area {
    padding: var(--spacing-md);
  }

  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }

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

  .item-row {
    grid-template-columns: 1fr;
  }

  .item-row input {
    margin-bottom: var(--spacing-xs);
  }

  .doc-header {
    flex-direction: column;
    gap: var(--spacing-md);
  }

  .doc-table {
    font-size: var(--font-size-xs);
  }

  .doc-table th,
  .doc-table td {
    padding: var(--spacing-xs);
  }

  /* Hide some table columns on mobile */
  .doc-table .hide-mobile {
    display: none;
  }

  .modal {
    width: 95%;
    max-height: 95vh;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: var(--spacing-md);
  }

  .topbar-actions {
    flex-direction: column;
    gap: var(--spacing-xs);
  }

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

  .list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    gap: 8px;
  }

  .list-item-content {
    flex: 1;
    min-width: 0;
  }

  .list-item-title {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .list-item-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 2px;
  }

  .list-item-meta .added-date {
    display: none;
  }

  .project-created-date {
    display: none;
  }

  .list-item-actions {
    flex-shrink: 0;
  }

  .list-item-actions .btn-secondary {
    padding: 4px 8px;
    font-size: 12px;
  }

  .project-meta {
    flex-direction: column;
    gap: var(--spacing-md);
  }

  .breadcrumb {
    font-size: var(--font-size-xs);
  }

  /* Mobile menu toggle */
  .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 28px;
    color: var(--color-text);
    cursor: pointer;
    padding: var(--spacing-md);
    margin: 0;
    min-width: 44px;
    min-height: 44px;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  }

  .breadcrumb {
    flex: 1;
    overflow: hidden;
  }

  .breadcrumb-item {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Hide sidebar sections on mobile */
  .sidebar-clients,
  .sidebar-projects {
    display: none !important;
  }

  /* ISSUE 1: Remove sticky/fixed positioning from project header */
  .project-header {
    position: relative;
    margin-bottom: 12px;
  }

  /* Unset max-height so stacked row-2 doesn't overflow into content below */
  .project-header-compact {
    max-height: none;
  }

  .project-header-compact .project-header-actions .btn-danger {
    display: none !important;
  }

  .project-header-compact .project-header-actions .btn-secondary {
    padding: 4px 10px;
    font-size: 12px;
  }

  .project-header-compact .project-header-row-1 {
    flex-wrap: wrap;
    gap: 4px;
  }

  .project-header-compact .project-header-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
  }

  /* Stack project header row 2 vertically */
  .project-header-row-2 {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--spacing-md);
  }

  .project-header-info {
    white-space: normal;
    width: 100%;
  }

  .project-header-progress {
    width: 100%;
    max-width: 100%;
  }

  /* Admin block delete buttons */
  .admin-block-done-compact .btn-delete-compact,
  .admin-block .btn-delete-block {
    display: none !important;
  }

  .admin-block-done-compact {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    flex-wrap: nowrap;
    overflow: hidden;
  }

  .admin-block-done-compact .document-badge-compact {
    display: none;
  }

  .admin-block-label-compact {
    flex: 1;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    max-width: calc(100% - 130px);
  }

  .document-badge-compact {
    flex-shrink: 0;
    font-size: 11px;
  }

  .status-select-compact {
    flex-shrink: 0;
    font-size: 11px;
    max-width: 110px;
  }

  /* ISSUE 2: Compact member cards */
  .member-item {
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 4px;
  }

  .member-info {
    gap: 8px;
  }

  .member-details {
    font-size: 12px;
  }

  .member-item .btn-icon,
  .member-item .btn-secondary {
    margin-top: 0;
    padding: 4px 8px;
    font-size: 12px;
  }

  /* ISSUE 3: Documents table - make scrollable */
  #documents-list,
  #documents-table-container,
  .invoices-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* Hide all stats except total value on mobile */
  .doc-stat-item {
    display: none;
  }

  .doc-total-value {
    display: block;
    font-size: 13px;
  }

  .documents-header {
    align-items: center;
  }

  /* Documents TYPE column - prevent wrapping */
  #documents-table-container td:first-child,
  #documents-table-container th:first-child {
    white-space: nowrap;
    font-size: 11px;
  }

  /* Documents table - hide Date (col 2) and Actions (col 4), show Type + Amount */
  #documents-table-container th:nth-child(2),
  #documents-table-container td:nth-child(2),
  #documents-table-container th:nth-child(4),
  #documents-table-container td:nth-child(4) {
    display: none;
  }

  /* Finance cards layout */
  .finance-cards-row-1 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .finance-cards-row-1 .finance-card:first-child {
    grid-column: 1 / -1;
  }

  .finance-cards-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .finance-card {
    min-width: 0;
  }
}

/* Small mobile - 480px */
@media (max-width: 480px) {
  :root {
    --font-size-2xl: 24px;
    --font-size-xl: 20px;
    --font-size-lg: 16px;
  }

  .auth-container {
    padding: var(--spacing-lg);
  }

  .card,
  .project-section {
    padding: var(--spacing-md);
  }

  .doc-summary {
    max-width: 100%;
  }

  .document-preview {
    padding: var(--spacing-md);
  }

  .doc-company-name {
    font-size: var(--font-size-lg);
  }

  .doc-type-badge {
    font-size: var(--font-size-base);
  }

  .receipt-amount-value {
    font-size: var(--font-size-xl);
  }

  h1 {
    font-size: var(--font-size-xl);
  }

  h2 {
    font-size: var(--font-size-lg);
  }
}

/* Desktop only elements */
@media (min-width: 769px) {
  .mobile-menu-toggle {
    display: none;
  }

  .sidebar-overlay {
    display: none !important;
  }
}

/* Print adjustments for mobile */
@media print and (max-width: 768px) {
  .doc-table .hide-mobile {
    display: table-cell;
  }

  .document-preview {
    padding: 10mm;
  }
}
