/* ============================================================
   MOBILE.CSS - Responsive styles for My Budget App
   ============================================================

   This file ONLY contains media queries for small screens.
   It does NOT modify anything on desktop/laptop.

   !important is used where style.css rules need to be overridden.

   BREAKPOINTS:
   - 768px = Tablets (iPad portrait)
   - 480px = Phones (iPhone)

   To disable all mobile styles, remove the <link> to mobile.css
   from index.html and everything reverts to the desktop layout.
   ============================================================ */


/* ============================================================
   TABLETS AND MEDIUM SCREENS (768px or less)
   ============================================================ */
@media (max-width: 768px) {

  /* ---- HEADER ---- */
  .header {
    padding: 10px 12px !important;
  }

  /* Hide "Personal Finance Tracker" subtitle */
  .logo-sub {
    display: none;
  }

  /* Smaller logo on tablet */
  .logo-img {
    width: 30px !important;
    height: 30px !important;
  }

  /* ---- MONTH NAV ---- */
  .month-nav button {
    padding: 5px 8px;
    font-size: 13px;
  }

  .month-label {
    min-width: 110px;
    font-size: 13px;
    padding: 5px 10px;
  }

  /* ---- NAV TABS ---- */
  .nav {
    padding: 4px 8px;
  }

  .nav button {
    padding: 6px 10px;
    font-size: 12px;
  }

  /* ---- MAIN CONTENT ---- */
  .content {
    padding: 12px !important;
  }

  /* ---- SEARCH INPUTS ---- */
  #bill-search,
  #master-search {
    width: 100% !important;
  }

  div:has(> #bill-search),
  div:has(> #master-search) {
    width: 100% !important;
    display: block !important;
  }

  /* ---- DASHBOARD: KPI grid 4 cols -> 2 cols on tablet ---- */
  .dash-kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  /* ---- DASHBOARD: Bills due/paid 3 cols -> 2 cols ---- */
  .dash-grid-3-stats {
    grid-template-columns: 1fr 1fr !important;
  }
}


/* ============================================================
   PHONES (480px or less)
   ============================================================ */
@media (max-width: 480px) {

  /* ---- PREVENT HORIZONTAL SCROLL ---- */
  html, body {
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }

  .content, .dash-wrap, .moneyin-wrap,
  .summary-wrap, .manage-wrap, .settings-wrap {
    max-width: 100% !important;
    overflow-x: clip !important;
    box-sizing: border-box !important;
  }

  /* ---- HEADER ---- */
  .header {
    padding: 8px 10px !important;
    gap: 4px !important;
    flex-wrap: nowrap !important;
    overflow: hidden !important;
  }

  /* Small logo on phone */
  .logo-img {
    width: 28px !important;
    height: 28px !important;
  }

  .logo-text {
    font-size: 14px !important;
  }

  .logo-sub {
    display: none !important;
  }

  /* Hide Admin + Logout from header — moved to hamburger menu */
  .header-user {
    display: none !important;
  }

  /* ---- MONTH NAV ---- */
  .month-nav {
    gap: 4px !important;
    position: static !important;
    transform: none !important;
    flex: 1;
    justify-content: center;
  }

  .month-nav button {
    padding: 4px 6px;
    font-size: 13px;
  }

  .month-label {
    min-width: 80px !important;
    font-size: 13px !important;
    padding: 4px 6px !important;
  }

  /* ---- HIDE NAV BAR — replaced by hamburger menu ---- */
  .nav {
    display: none !important;
  }

  /* ---- HAMBURGER BUTTON ---- */
  .hamburger-btn {
    background: none;
    border: none;
    font-size: 32px;
    color: var(--green);
    cursor: pointer;
    padding: 2px 4px;
    line-height: 1;
    font-weight: 700;
    flex-shrink: 0;
    margin-bottom: 8px;
  }

  /* ---- DROPDOWN MENU ---- */
  .mobile-menu {
    display: none;
    position: fixed;
    top: 46px;
    right: 0;
    width: 220px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 0 0 0 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 200;
    overflow: hidden;
  }

  .mobile-menu.open {
    display: block;
  }

  .mobile-menu-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
  }

  .mobile-menu-header .admin-label {
    color: var(--green);
    font-weight: 600;
    font-size: 14px;
  }

  .mobile-menu-header .logout-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 12px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text);
    font-family: inherit;
  }

  .mobile-menu-item {
    display: block;
    width: 100%;
    padding: 14px 16px;
    border: none;
    border-bottom: 1px solid var(--border-light);
    background: #fff;
    font-size: 15px;
    color: var(--text);
    text-align: center;
    cursor: pointer;
    font-family: inherit;
  }

  .mobile-menu-item:last-child {
    border-bottom: none;
  }

  .mobile-menu-item.active {
    color: var(--green);
    font-weight: 600;
    background: var(--green-light);
  }

  .mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.2);
    z-index: 199;
  }

  .mobile-menu-overlay.open {
    display: block;
  }

  /* ---- MAIN CONTENT ---- */
  .content {
    padding: 10px 16px !important;
  }

  .section-title {
    font-size: 16px !important;
  }

  /* ---- CARDS ---- */
  .card {
    padding: 12px;
  }

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

  /* ---- DASHBOARD: KPI grid 4 cols -> 2 cols on phone ---- */
  .dash-kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  /* ---- DASHBOARD: Bills due/paid 3 cols -> 1 col ---- */
  .dash-grid-3-stats {
    grid-template-columns: 1fr !important;
  }

  /* ---- DASHBOARD: Charts row 3 cols -> 1 col ---- */
  .dash-grid-3 {
    grid-template-columns: 1fr !important;
  }

  /* ---- DASHBOARD: Chart heights on mobile ---- */
  .chart-h180 { height: 220px !important; }
  .chart-h120 { height: 160px !important; }

  /* ---- SUMMARY: 2-column grids -> 1 column ---- */
  .summary-grid-2,
  .summary-grid-2-last {
    grid-template-columns: 1fr !important;
  }

  /* ---- FORMS ---- */
  .form-grid {
    grid-template-columns: 1fr !important;
  }

  /* ---- BILLS TABLE ---- */
  th {
    font-size: 9px;
    padding: 6px 4px;
  }

  td {
    padding: 6px 4px;
  }

  /* ---- SUMMARY ROWS ---- */
  .summary-row    { padding: 8px 0; }
  .summary-label  { font-size: 14px; }
  .summary-value  { font-size: 14px; }

  /* Via CC badge on its own line on mobile */
  .via-badge { display: block; margin-top: 2px; }
}


/* ============================================================
   MOBILE CARD STYLES
   Used by mobile.js when transforming tables into cards.
   Active on screens 480px or less.
   ============================================================ */

@media (max-width: 480px) {

  .mobile-cards-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
  }

  .mobile-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  }

  /* Blue tint — bill has amount paid entered */
  .mobile-card-ready {
    background: var(--blue-light);
  }

  /* Gold tint — bill is marked paid */
  .mobile-card-paid {
    background: var(--paid-bg);
  }

  /* 2-column grid for field pairs */
  .mobile-card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 16px;
    margin-bottom: 12px;
  }

  .mobile-card-grid:last-child {
    margin-bottom: 0;
  }

  /* 3-column grid for Due | Paid | Delete row */
  .mobile-card-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 4px 8px;
    align-items: end;
    text-align: center;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    margin-top: 4px;
  }

  /* 4-column grid for Due | Paid | Clear | Delete row */
  .mobile-card-grid-4 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 4px 8px;
    align-items: end;
    text-align: center;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    margin-top: 4px;
  }

  /* 5-column grid for Due | Paid | Clear | Session | Delete row */
  .mobile-card-grid-5 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
    gap: 4px 6px;
    align-items: end;
    text-align: center;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    margin-top: 4px;
  }

  .mobile-card-field {
    min-width: 0;
  }

  .mobile-card-label {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    margin-bottom: 2px;
  }

  .mobile-card-value {
    font-size: 14px;
    color: var(--text);
  }

  .mobile-card-value input[type="text"] {
    border: 1px solid var(--border) !important;
    background: #fff !important;
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 14px;
    width: 100%;
    min-width: 0;
    height: 32px;
  }

  .mobile-card-value input[type="text"]:focus {
    border-color: var(--green) !important;
  }

  .mobile-card-value select {
    border: 1px solid var(--border) !important;
    background: #fff !important;
    border-radius: 4px;
    padding: 4px 6px;
    font-size: 13px;
    width: 100%;
    min-width: 0;
    height: 32px;
  }

  .mobile-card-value .check-btn {
    width: 28px;
    height: 28px;
  }

  .mobile-card-value .del-btn {
    font-size: 20px;
    opacity: 0.6;
  }
  .mobile-card-value .del-btn svg { width: 18px; height: 18px; }

  .mobile-card-value .tag {
    font-size: 9px;
  }
}

/* Disable bounce/elastic scroll */
html, body { overscroll-behavior: none; }

/* Show short month name on phone, hide full name */
@media (max-width: 480px) {
  .month-full  { display: none !important; }
  .month-short { display: inline !important; }
}

/* ---- DEPOSIT FORM (Add/Edit deposit) — stack fields vertically ---- */
@media (max-width: 480px) {
  .deposit-form-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }

  /* Last item (Add button) spans full width */
  .deposit-form-grid > *:last-child {
    grid-column: 1 / -1 !important;
  }

  .card-new-deposit,
  .card-edit-deposit {
    max-width: 100% !important;
  }
}
