/* ============================================================================
   FamilyBook — Mobile & Tablet Responsive Stylesheet (PWA App Experience)
   ============================================================================ */

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    width: 276px;
    z-index: 60;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.45);
  }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    z-index: 55;
  }
  .sidebar-overlay.open { display: block; }

  .main-area {
    margin-left: 0;
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 18px);
  }

  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
  }

  .topbar {
    padding: 8px 12px;
    height: auto;
    min-height: 58px;
    gap: 8px;
  }

  .search-kbd { display: none; }
  .global-search-input {
    padding: 9px 12px 9px 34px;
    font-size: 14px;
  }

  .topbar-actions .hide-mobile { display: none !important; }
  .topbar-actions .btn-sm { padding: 7px 10px; font-size: 12px; }

  .page-content {
    padding: 14px 12px 24px;
  }

  .page-header {
    margin-bottom: 14px;
    gap: 10px;
  }
  .page-title { font-size: 19px; }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .kpi-card { padding: 12px 13px; }
  .kpi-value { font-size: 19px; }

  /* Native-style Mobile Bottom Navigation Bar */
  .mobile-bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 45;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 18px rgba(15, 23, 42, 0.08);
  }

  .mobile-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 52px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 10.5px;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    border-radius: 10px;
    position: relative;
  }
  .mobile-nav-btn.active {
    color: var(--accent);
    background: var(--accent-soft);
  }
  .mobile-nav-dot {
    position: absolute;
    top: 5px;
    right: 14px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 99px;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
  }

  /* Floating Action Button on Mobile */
  .mobile-fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 16px;
    bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 14px);
    width: 54px;
    height: 54px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 26px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(16, 128, 0, 0.38);
    cursor: pointer;
    z-index: 46;
    transition: transform 0.14s ease;
  }
  .mobile-fab:active { transform: scale(0.94); }

  /* Toast sits above bottom nav & FAB */
  .toast-container {
    bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 76px);
    left: 12px;
    right: 12px;
  }

  /* Bottom-sheet Modals on Mobile */
  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }
  .modal, .modal.modal-sm, .modal.modal-lg, .modal.modal-xl {
    max-width: 100%;
    max-height: 92dvh;
    border-radius: 18px 18px 0 0;
    animation: sheetUp 0.2s ease-out;
  }
  @keyframes sheetUp {
    from { transform: translateY(36px); opacity: 0.5; }
    to { transform: translateY(0); opacity: 1; }
  }
  .modal-body { padding: 14px 14px; }
  .modal-header { padding: 13px 16px; }
  .modal-footer {
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  }

  /* Prevent iOS Safari zoom on input focus */
  input, select, textarea, .form-control {
    font-size: 16px !important;
  }

  .filter-bar {
    padding: 10px;
    gap: 8px;
  }
  .filter-bar select, .filter-bar input {
    width: 100%;
    min-height: 42px;
  }
}

/* Stacked Mobile Card Tables on Small Phones */
@media (max-width: 680px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-grid .kpi-card.highlight { grid-column: 1 / -1; }

  .entry-card-top { padding: 13px 14px; }
  .entry-card-meta { padding: 8px 14px; gap: 8px 12px; }
  .entry-card-breakdown { padding: 10px 14px; }

  table.responsive-table thead { display: none; }
  table.responsive-table,
  table.responsive-table tbody,
  table.responsive-table tr,
  table.responsive-table td {
    display: block;
    width: 100%;
  }
  table.responsive-table tr {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border-color);
  }
  table.responsive-table td {
    padding: 4px 0;
    border: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    text-align: right;
  }
  table.responsive-table td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
  }
  table.responsive-table td[data-label=""]::before,
  table.responsive-table td.mobile-full::before {
    display: none;
  }
  table.responsive-table td.mobile-full {
    display: block;
    text-align: left;
  }

  .pdf-paper-preview {
    padding: 14px;
  }
}
