/* Mobile-only app-like UI overrides */

/* Load only on <=768px via <link media> */
:root {
  --mobile-bottom-nav-height: 64px;
}

/* Base adjustments */
body.is-mobile {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  font-size: 16px;
}

@media (max-width: 768px) {
  /* Layout spacing to avoid overlap with bottom nav */
  .main-content,
  main.container,
  main.container-fluid {
    padding-bottom: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom, 0px));
  }

  /* Hide header Contact on mobile; moved to profile menu */
  .header .contact-btn { display: none !important; }

  /* Header tweaks */
  .header { padding: 10px 0; }
  .header h5 { font-size: 1.05rem; }

  /* Business insights: show text section, hide metric cards and charts */
  .mobile-insights { display: block; background: #fff; border-radius: 12px; padding: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); margin-bottom: 12px; }
  .mobile-insights .title { font-weight: 700; color: #1f2937; }
  .mobile-insights .insights-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .mobile-insights .insight-item { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px; padding: 10px; }
  .mobile-insights .label { display: block; font-size: 11px; color: #6b7280; margin-bottom: 4px; }
  .mobile-insights .value { display: block; font-weight: 700; color: #111827; font-size: 1rem; }
  .mobile-insights .meta { display: block; font-size: 11px; color: #6b7280; }
  .metrics-row { display: none !important; }
  .chart-controls, .charts-section, .chart-container { display: none !important; }

  /* Buttons and inputs: larger touch targets */
  .btn { min-height: 44px; border-radius: 12px; }
  .btn.btn-sm { min-height: 36px; }
  .form-control, .form-select { min-height: 44px; border-radius: 12px; }

  /* Make primary actions full-width inside forms */
  form .btn-primary,
  form .btn-success,
  form .btn-danger,
  .modal-footer .btn-primary { width: 100%; }

  /* Cards tighter paddings */
  .card-body { padding: 14px; }

  /* Tables: dashboard activity fits without horizontal scroll */
  .dashboard-activity-table { table-layout: fixed; font-size: 12px; width: 100%; }
  .dashboard-activity-table th, .dashboard-activity-table td { padding: 8px 6px; }
  .dashboard-activity-table .col-time { width: 56px; white-space: nowrap; }
  .dashboard-activity-table .col-amount { width: 84px; white-space: nowrap; text-align: right; }
  .dashboard-activity-table .col-desc, .dashboard-activity-table .col-type { display: none; }
  .dashboard-activity-table .col-name, .dashboard-activity-table .col-activity { word-break: break-word; }

  /* Remove fixed height/scroll from today's activity on mobile */
  .recent-activity-card.fixed-height { height: auto !important; min-height: auto !important; overflow: visible !important; }
  .recent-activity-card.fixed-height .table-responsive { max-height: none !important; overflow: visible !important; }

  /* Generic table tweaks on mobile */
  .table-responsive { border-radius: 12px; overflow-x: hidden; }

  /* Full-width containers on mobile */
  .container, .container-sm, .container-md, .container-lg, .container-xl, .container-xxl, .container-fluid {
    max-width: 100% !important;
    padding-left: 10px !important;
    padding-right: 10px !important;
  }
  .row { margin-left: -6px; margin-right: -6px; }
  [class*='col-'] { padding-left: 6px; padding-right: 6px; }

  /* Make tables fit without horizontal scroll across app */
  table.table { table-layout: fixed; font-size: 12px; width: 100%; border-collapse: separate; border-spacing: 0; background: #fff; }
  table.table th, table.table td { padding: 8px 6px; }
  table.table th, table.table td { word-break: normal; overflow-wrap: break-word; white-space: normal; hyphens: auto; }
  table.table .actions, table.table .text-end { white-space: nowrap; }

  /* Mobile table redesign: dense grid, clear separation */
  table.table thead th { background: #f9fafb; color: #6b7280; font-size: 11px; font-weight: 600; border-bottom: 1px solid #eef2f7; }
  table.table tbody td { vertical-align: top; }
  table.table tbody tr:nth-child(even) td { background: #fcfcfd; }
  table.table tbody td:not(:last-child) { border-right: 1px solid #eef2f7; }
  table.table tbody tr + tr td { border-top: 1px solid #eef2f7; }

  /* Consolidated amounts cell styling */
  .cell-amounts { white-space: nowrap; font-size: 11px; }
  .cell-amounts .amt { font-weight: 600; }
  .cell-amounts .ch { color: #059669; }
  .cell-amounts .co { color: #d97706; }
  .cell-amounts .pr { color: #dc2626; }
  .cell-amounts .sep { color: #94a3b8; margin: 0 4px; }

  /* Truncate long text gracefully (no letter-by-letter breaks) */
  .td-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; word-break: normal; }
  .clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: normal; word-break: normal; }
  .no-letter-break { word-break: normal; overflow-wrap: break-word; }

  /* Compact buttons/badges inside tables */
  table.table .btn, table.table .btn-sm { padding: 4px 8px; font-size: 11px; border-radius: 6px; }
  table.table .badge { font-size: 10px; padding: 4px 6px; border-radius: 6px; }

  /* Action toggle (collapse actions into icon) */
  td.action-cell { position: relative; }
  .action-toggle { background: transparent; border: none; padding: 6px; border-radius: 6px; color: #475569; }
  .action-toggle i { font-size: 16px; }
  .action-panel { display: none; gap: 6px; margin-top: 4px; }
  .action-panel.open { display: inline-flex; flex-wrap: wrap; }

  /* Quick Actions: icon + label only */
  .qa-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .qa-btn { background: transparent !important; border: none !important; box-shadow: none !important; height: auto !important; padding: 6px !important; color: #374151 !important; display: flex; flex-direction: column; align-items: center; justify-content: center; }
  .qa-btn i { font-size: 22px !important; line-height: 1; }
  .qa-btn span { font-size: 11px; margin-top: 4px; line-height: 1.1; color: #4b5563; }
  .qa-btn.add-profit i { color: #10b981; }
  .qa-btn.add-expense i { color: #ef4444; }
  .qa-btn.view-customers i { color: #3b82f6; }
  .qa-btn.create-invoice i { color: #8b5cf6; }
  .qa-btn.qa-balance i { color: #f59e0b; }
  .qa-btn.btn-info i { color: #06b6d4; }
  .qa-btn.qa-debt i { color: #f97316; }

  /* Bottom navigation */
  .mobile-bottom-nav { 
    position: fixed !important; 
    left: 0; right: 0; bottom: 0; top: auto; 
    width: 100vw; 
    height: var(--mobile-bottom-nav-height); 
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: #fff; 
    border-top: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 -6px 20px rgba(0,0,0,0.08);
    z-index: 1070; 
    display: flex; 
    align-items: center; 
    justify-content: space-around;
  }
  .mobile-bottom-nav a { 
    flex: 1; 
    text-align: center; 
    text-decoration: none; 
    color: #6b7280; 
    font-size: 11px; 
    line-height: 1.1; 
  }
  .mobile-bottom-nav a .icon { 
    display: block; 
    font-size: 18px; 
    margin-bottom: 4px; 
  }
  .mobile-bottom-nav a.active, .mobile-bottom-nav a:focus { color: #2563eb; }
}

@media (min-width: 769px) {
  .mobile-bottom-nav { display: none; }
}
