/**
 * RESPONSIVE.CSS - FULLSCREEN VERSION
 * Mobile-First Responsive Design for Fullscreen App
 * 
 * Breakpoints:
 * - Mobile: < 768px
 * - Tablet: 768px - 1024px  
 * - Desktop: > 1024px
 */

/* ============================================
   FULLSCREEN BASE (NO CHANGES NEEDED)
   ============================================ */

/* Container is already fullscreen - no overrides needed */
.container {
  max-width: none !important;
  margin: 0 !important;
  border-radius: 0 !important;
}

/* Body padding removed for fullscreen */
body {
  padding: 0 !important;
}

/* ============================================
   MOBILE NAVIGATION (HAMBURGER MENU)
   ============================================ */

/* Mobile menu toggle button */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1001;
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  width: 48px;
  height: 48px;
  align-items: center;
  justify-content: center;
}

@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: flex;
  }
}

/* Hamburger icon */
.hamburger-icon {
  width: 24px;
  height: 20px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hamburger-icon span {
  display: block;
  height: 3px;
  background: white;
  border-radius: 2px;
  transition: all 0.3s ease;
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(1) {
  transform: rotate(45deg) translate(7px, 7px);
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(2) {
  opacity: 0;
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -7px);
}

/* ============================================
   HEADER RESPONSIVE
   ============================================ */

/* Mobile header adjustments */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
  }

  .header-left {
    width: 100%;
  }

  #appTitle {
    font-size: 18px;
  }

  .header-right {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }

  .profile-pill {
    flex: 1 1 100%;
    justify-content: space-between;
  }

  .profile-left {
    flex: 1;
  }

  .profile-actions {
    flex-wrap: wrap;
  }

  .pill-btn {
    font-size: 12px;
    padding: 6px 10px;
    white-space: nowrap;
  }

  #statusIndicator {
    flex: 1 1 100%;
    justify-content: center;
  }
}

/* Tablet header */
@media (min-width: 768px) and (max-width: 1024px) {
  .header {
    gap: 12px;
  }

  #appTitle {
    font-size: 20px;
  }

  .pill-btn {
    font-size: 13px;
  }
}

/* ============================================
   TABS/NAVIGATION RESPONSIVE
   ============================================ */

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding-bottom: 4px;
}

/* Mobile: Vertical navigation overlay */
@media (max-width: 768px) {
  .tabs {
    position: fixed;
    top: 0;
    left: -100%;
    width: 280px;
    height: 100vh;
    flex-direction: column;
    background: white;
    z-index: 1000;
    padding: 80px 16px 16px 16px;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.15);
    transition: left 0.3s ease;
    overflow-y: auto;
    margin-bottom: 0;
  }

  .tabs.mobile-menu-open {
    left: 0;
  }

  .tab {
    width: 100%;
    justify-content: flex-start;
    padding: 14px 16px;
    border-radius: 8px;
    font-size: 15px;
  }

  .tab.active {
    background: var(--primary-color);
    color: white;
  }
  
  /* Tab content padding for mobile */
  .tab-content {
    padding: 16px;
  }
}

/* Tablet: Horizontal scrolling tabs */
@media (min-width: 768px) and (max-width: 1024px) {
  .tabs {
    gap: 6px;
    flex-wrap: nowrap;
  }

  .tab {
    flex-shrink: 0;
    padding: 10px 14px;
    font-size: 13px;
  }
}

/* Desktop: Full width tabs */
@media (min-width: 1024px) {
  .tabs {
    flex-wrap: wrap;
  }

  .tab {
    padding: 12px 20px;
    font-size: 14px;
  }
}

/* Mobile menu overlay backdrop */
.mobile-menu-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
}

@media (max-width: 768px) {
  .mobile-menu-backdrop.active {
    display: block;
  }
}

/* ============================================
   FORMS RESPONSIVE
   ============================================ */

/* Mobile: Stack form fields vertically */
@media (max-width: 768px) {
  /* Grid forms to single column */
  [style*="display: grid"][style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Invoice form specific */
  .invoice-item-row {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    padding: 12px !important;
  }

  /* Input groups */
  .input-group,
  .checkbox-group {
    width: 100%;
  }

  /* Buttons full width on mobile */
  .btn-primary,
  .btn-secondary,
  .auth-btn {
    width: 100%;
    padding: 12px 16px;
  }

  /* Form labels */
  label {
    font-size: 13px;
  }

  /* Inputs */
  input,
  textarea,
  select {
    font-size: 16px !important; /* Prevents iOS zoom */
    padding: 12px !important;
  }
}

/* Tablet: 2 column layout where appropriate */
@media (min-width: 768px) and (max-width: 1024px) {
  [style*="grid-template-columns: 1fr 1fr 1fr"] {
    grid-template-columns: 1fr 1fr !important;
  }

  .invoice-item-row {
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto !important;
  }
}

/* ============================================
   TABLES RESPONSIVE
   ============================================ */

/* Horizontal scroll for tables on mobile */
.table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
  table {
    min-width: 600px;
  }

  /* Make table text smaller */
  table {
    font-size: 12px;
  }

  th,
  td {
    padding: 8px 6px !important;
  }

  /* Hide less important columns on mobile */
  .hide-mobile {
    display: none;
  }
}

/* Card-style layout for mobile tables */
@media (max-width: 768px) {
  .mobile-card-view {
    display: block;
  }

  .mobile-card-view table {
    display: none;
  }

  .mobile-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }

  .mobile-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e2e8f0;
  }

  .mobile-card-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .mobile-card-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
  }

  .mobile-card-label {
    font-weight: 600;
    color: #64748b;
  }

  .mobile-card-value {
    color: #0f172a;
    text-align: right;
  }
}

/* ============================================
   MODALS RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  .modal-content {
    width: 95% !important;
    max-width: none !important;
    margin: 5% auto;
    max-height: 90vh;
    overflow-y: auto;
  }

  .modal-header h2 {
    font-size: 18px;
  }

  .modal {
    padding: 0;
  }
}

@media (min-width: 768px) and (max-width: 1024px) {
  .modal-content {
    width: 85% !important;
    max-width: 700px !important;
  }
}

/* ============================================
   CARDS/STATS RESPONSIVE
   ============================================ */

/* Stats cards */
@media (max-width: 768px) {
  .stats-grid,
  [style*="display: grid"][style*="grid-template-columns: repeat(4"] {
    grid-template-columns: 1fr 1fr !important;
    gap: 12px !important;
  }

  .stat-card {
    padding: 14px !important;
  }

  .stat-card h3 {
    font-size: 13px !important;
  }

  .stat-card .stat-value {
    font-size: 20px !important;
  }
}

@media (min-width: 768px) and (max-width: 1024px) {
  [style*="grid-template-columns: repeat(4"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ============================================
   BUTTONS RESPONSIVE
   ============================================ */

/* Mobile: Stack button groups */
@media (max-width: 768px) {
  .button-group,
  [style*="display: flex"][style*="gap"] {
    flex-direction: column;
    width: 100%;
  }

  .button-group button,
  .button-group a {
    width: 100%;
  }

  /* Icon-only buttons on mobile */
  .btn-icon-text .btn-text {
    display: none;
  }

  .btn-icon {
    padding: 10px !important;
    width: auto !important;
  }
}

/* Tablet: Wrap buttons */
@media (min-width: 768px) and (max-width: 1024px) {
  .button-group {
    flex-wrap: wrap;
  }
}

/* ============================================
   DASHBOARD WIDGETS RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  .dashboard-grid,
  [class*="dashboard"] [style*="display: grid"] {
    grid-template-columns: 1fr !important;
  }

  /* Chart containers */
  .chart-container {
    height: 250px !important;
  }

  /* Widget headers */
  .widget-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 12px !important;
  }
}

@media (min-width: 768px) and (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .chart-container {
    height: 300px !important;
  }
}

/* ============================================
   INVOICE VIEW RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  /* Invoice header */
  .invoice-header {
    flex-direction: column !important;
    gap: 16px !important;
  }

  /* Invoice actions */
  .invoice-actions {
    flex-direction: column;
    gap: 8px;
  }

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

  /* Invoice details grid */
  .invoice-details-grid {
    grid-template-columns: 1fr !important;
  }

  /* Company info and customer info side by side becomes stacked */
  .invoice-info-row {
    flex-direction: column !important;
  }
}

/* ============================================
   SETTINGS MODAL RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  #settingsModal .modal-content {
    padding: 16px;
  }

  #settingsForm > div {
    margin-bottom: 16px !important;
  }

  #settingsForm label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 13px;
  }

  #settingsForm input,
  #settingsForm textarea,
  #settingsForm select {
    width: 100%;
  }
}

/* ============================================
   AUTH FORMS RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  .auth-container {
    padding: 16px;
  }

  .auth-box {
    width: 100% !important;
    max-width: none !important;
    padding: 24px 16px;
  }

  .auth-box h2 {
    font-size: 20px;
  }

  .auth-tabs {
    gap: 8px;
  }

  .auth-tab {
    flex: 1;
    font-size: 14px;
    padding: 10px;
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* Hide on mobile */
@media (max-width: 768px) {
  .hide-mobile {
    display: none !important;
  }
}

/* Hide on tablet */
@media (min-width: 768px) and (max-width: 1024px) {
  .hide-tablet {
    display: none !important;
  }
}

/* Hide on desktop */
@media (min-width: 1024px) {
  .hide-desktop {
    display: none !important;
  }

  .mobile-only {
    display: none !important;
  }
}

/* Show only on mobile */
@media (min-width: 768px) {
  .mobile-only {
    display: none !important;
  }
}

/* Responsive text sizes */
.text-responsive {
  font-size: clamp(14px, 2vw, 18px);
}

.heading-responsive {
  font-size: clamp(20px, 4vw, 32px);
}

/* Touch-friendly tap targets */
@media (max-width: 768px) {
  button,
  a,
  .clickable {
    min-height: 44px;
    min-width: 44px;
  }
}

/* Responsive padding */
.padding-responsive {
  padding: clamp(12px, 3vw, 24px);
}

/* Responsive gap */
.gap-responsive {
  gap: clamp(8px, 2vw, 16px);
}

/* ============================================
   SCROLLBAR STYLING (MOBILE)
   ============================================ */

@media (max-width: 768px) {
  /* Thin scrollbars on mobile */
  ::-webkit-scrollbar {
    width: 4px;
    height: 4px;
  }

  ::-webkit-scrollbar-track {
    background: #f1f1f1;
  }

  ::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 2px;
  }

  ::-webkit-scrollbar-thumb:hover {
    background: #555;
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  body {
    background: white;
    padding: 0;
  }

  body::before {
    display: none;
  }

  .container {
    box-shadow: none;
    max-width: 100%;
  }

  .header,
  .tabs,
  .mobile-menu-toggle,
  .mobile-menu-backdrop,
  button,
  .hide-print {
    display: none !important;
  }

  .tab-content {
    page-break-inside: avoid;
  }

  table {
    page-break-inside: auto;
  }

  tr {
    page-break-inside: avoid;
    page-break-after: auto;
  }
}

/* ============================================
   LANDSCAPE ORIENTATION (MOBILE)
   ============================================ */

@media (max-width: 768px) and (orientation: landscape) {
  .header {
    padding-bottom: 8px;
  }

  .tabs {
    padding: 60px 16px 16px 16px;
  }

  .modal-content {
    max-height: 85vh;
  }
}

/* ============================================
   ACCESSIBILITY IMPROVEMENTS
   ============================================ */

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --primary-color: #0050a0;
    --border-color: #000;
  }

  button,
  .tab,
  .btn-primary {
    border: 2px solid currentColor;
  }
}