/**
 * responsive.css — Makes the app fit any screen: laptop, tablet, phone.
 * Loaded LAST so it can adjust the base styles.
 *
 * Breakpoints
 *   ≥ 1100px   laptop / desktop  — full sidebar, content wraps instead of clipping
 *   768–1099px tablet            — icon-only sidebar, single-column layouts
 *   < 768px    phone             — slide-out menu + top bar, stacked forms, full-screen modals
 */

/* ════════════════════════════════════════════════════════════════════════════
   ALL SIZES — never clip content
   ════════════════════════════════════════════════════════════════════════════ */
:root {
  --tab-py: 28px;
  --tab-px: 32px;
}

.app-shell { height: 100vh; height: 100dvh; }
.main-area { min-width: 0; }           /* lets flex child shrink instead of overflowing */
.tab { padding: var(--tab-py) var(--tab-px); }

/* Page header: wraps onto more lines instead of pushing controls off-screen */
.pg-head {
  margin: calc(-1 * var(--tab-py)) calc(-1 * var(--tab-px)) 20px;
  padding: 12px var(--tab-px);
  flex-wrap: wrap;
  gap: 10px 16px;
}
.pg-title { min-width: 0; flex-wrap: wrap; }
.pg-actions { flex-wrap: wrap; justify-content: flex-end; }

/* Toolbars and button rows wrap too */
#txn-filter-bar,
#txn-actions,
.hero-btns,
.hero-features,
.cust-select-toolbar,
#dash-panel-daily > .d-flex:first-child { flex-wrap: wrap; }

/* Tables scroll sideways inside their card instead of cutting off columns */
.tbl-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl-card > .tbl { min-width: 100%; }
.section-card { min-width: 0; }
.rel-calc-section { overflow-x: auto; }

/* Grid columns may shrink below their content's width (otherwise one wide
   table stretches the whole page past the screen edge) */
.txn-grid > *, .dash-row > *, .txn-main > *, .txn-side > * { min-width: 0; }

/* Customer list: text may wrap (one long name must not push other columns off-screen),
   and the Father/Husband cell is compact */
#cust-tbody td { white-space: normal; overflow-wrap: anywhere; }
#cust-tbody td[data-cell="phone"] { white-space: nowrap; }
#cust-tbody td[data-cell="father"] .f-lbl { margin-bottom: 0; font-size: 0.6rem; }
#cust-tbody td[data-cell="father"] br { display: none; }

/* Long text in info rows wraps instead of overflowing */
.sc-val { overflow-wrap: anywhere; }
.dc-val { overflow-wrap: anywhere; }

/* Charts and images never wider than their container */
canvas, .evi-img { max-width: 100%; }

/* Flexible widths for fixed-size inputs */
.search-field input { max-width: 100%; }
.login-box { width: min(340px, 92vw); }
.cam-device-select { max-width: 80vw; }

/* Mobile top bar + menu backdrop: hidden on large screens */
.mobile-topbar,
.sb-backdrop { display: none; }

/* ════════════════════════════════════════════════════════════════════════════
   LAPTOP (≤ 1366px) — e.g. 1366×768 at 100% zoom
   ════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1366px) {
  :root { --tab-py: 22px; --tab-px: 24px; }
  .sidebar { width: 190px; }
  .search-field input { width: 210px; }
  .search-field input:focus { width: 240px; }
  .sel-filter { min-width: 110px; }
  .tbl th, .tbl td { padding: 10px 12px; }
  .txn-grid { grid-template-columns: 1fr 320px; }
  .dc-info { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}

/* Laptop customer list: Aadhaar column hidden so the rest fits (it is on the customer page) */
@media (max-width: 1400px) {
  #cust-tbl-card th:nth-child(7), #cust-tbl-card td:nth-child(7) { display: none; }
}

/* Customer list header: title on its own line, filters wrap below */
@media (max-width: 1500px) {
  #view-customer-list .pg-head { align-items: flex-start; }
  #view-customer-list .pg-actions { justify-content: flex-start; width: 100%; }
}

/* ════════════════════════════════════════════════════════════════════════════
   TABLET (≤ 1099px) — icon-only sidebar, single-column layouts
   ════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1099px) {
  :root { --tab-py: 18px; --tab-px: 18px; }

  .sidebar { width: 68px; padding: 14px 8px; }
  .sb-brand { justify-content: center; padding: 8px 0 20px; }
  .sb-brand span,
  .sb-item span,
  .sb-user-text,
  .theme-switch .fa-sun,
  .theme-switch .fa-moon { display: none; }
  .sb-item { justify-content: center; padding: 12px 0; }
  .sb-viewas { margin: -6px 0 12px; padding: 6px 4px; }
  .sb-viewas-lbl { justify-content: center; margin-bottom: 4px; }
  .sb-viewas-lbl span { display: none; }
  .sb-viewas-select { padding: 4px 2px; font-size: 0.7rem !important; }
  .sb-item i { font-size: 1.05rem; width: auto; }
  .sb-footer { padding: 6px 0; }
  .sb-user-info { flex-direction: column; padding: 6px 0; gap: 4px; }
  .sb-user-info #btn-logout { margin-left: 0 !important; }

  .txn-grid { grid-template-columns: 1fr; }
  .dash-row { grid-template-columns: 1fr; }
  .detail-card { flex-wrap: wrap; }
  .detail-card .dc-info { flex: 1 1 260px; }
  .detail-card #btn-new-txn { margin-left: auto; }

  .search-field { flex: 1 1 200px; }
  .search-field input,
  .search-field input:focus { width: 100%; }

  /* Tablet customer list: also hide Guarantor + Category */
  #cust-tbl-card th:nth-child(8), #cust-tbl-card td:nth-child(8),
  #cust-tbl-card th:nth-child(9), #cust-tbl-card td:nth-child(9) { display: none; }
}

/* ════════════════════════════════════════════════════════════════════════════
   PHONE (≤ 767px) — top bar + slide-out menu, stacked everything
   ════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
  :root { --tab-py: 14px; --tab-px: 12px; }
  body { font-size: 15px; }

  /* App shell becomes a column: top bar, then content */
  .app-shell { flex-direction: column; }
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 54px;
    padding: 0 12px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 1040;
  }
  .mobile-topbar .mt-brand {
    font-weight: 800;
    color: var(--accent);
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .mobile-topbar .mt-page {
    margin-left: auto;
    font-size: 0.82rem;
    color: var(--text3);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 45vw;
  }
  .mt-menu-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    background: var(--bg3);
    color: var(--text);
    border-radius: 10px;
    font-size: 1.1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Sidebar slides in from the left (full labels again) */
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 260px;
    max-width: 82vw;
    padding: 18px 12px;
    z-index: 1060;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: var(--sh2);
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sb-brand { justify-content: flex-start; padding: 8px 12px 20px; }
  .sb-viewas { margin: -8px 4px 14px; padding: 8px; }
  .sb-viewas-lbl { justify-content: flex-start; }
  .sb-viewas-lbl span { display: inline; }
  .sb-viewas-select { padding: 8px; font-size: 16px !important; }
  .sb-brand span,
  .sb-item span,
  .sb-user-text { display: initial; }
  .sb-user-text { display: flex; }
  .theme-switch .fa-sun,
  .theme-switch .fa-moon { display: inline-block; }
  .sb-item { justify-content: flex-start; padding: 12px 14px; font-size: 0.95rem; }
  .sb-user-info { flex-direction: row; padding: 8px; }
  .sb-user-info #btn-logout { margin-left: auto !important; }

  .sb-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1050;
  }
  .sb-backdrop.show { display: block; }

  .main-area { flex: 1; min-height: 0; }

  /* Page header: stacked, full-width controls */
  .pg-head { position: static; }
  .pg-title { font-size: 1rem; }
  .pg-actions { width: 100%; justify-content: flex-start; }
  .pg-actions > * { flex: 1 1 auto; }
  .pg-actions .search-field { flex: 1 1 100%; }
  .sel-filter { flex: 1 1 calc(50% - 8px); min-width: 0; width: auto; }
  #f-guarantor-filter { width: auto !important; }
  .pg-actions .btn-accent,
  .pg-actions .btn-glass,
  .pg-actions .btn-danger-sm { justify-content: center; }

  /* Buttons: comfortable touch targets */
  .btn-accent, .btn-glass { padding: 10px 14px; }
  .btn-accent.btn-sm, .btn-glass.btn-sm, .btn-danger-sm { padding: 8px 12px; }
  .btn-icon { width: 38px; height: 38px; }
  .btn-icon.sm { width: 32px; height: 32px; }

  /* Inputs at 16px stop iOS from zooming in on focus */
  input, select, textarea, .form-control, .form-select { font-size: 16px !important; }

  /* Cards & grids */
  .metrics-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .metric-card { padding: 12px; gap: 10px; }
  .mc-icon { width: 36px; height: 36px; font-size: 0.95rem; }
  .mc-val { font-size: 1.05rem; overflow-wrap: anywhere; }
  .dash-panel, .section-card { padding: 14px; }
  .detail-card { padding: 16px; gap: 14px; }
  .detail-card .dc-info { grid-template-columns: 1fr 1fr; gap: 12px; }
  .detail-card #btn-new-txn { width: 100%; justify-content: center; margin-left: 0; }
  .sc-row { gap: 12px; }
  .sc-evidence { flex-wrap: wrap; }

  /* Customer list: each customer becomes a compact card
       [photo] NAME ................ STATUS
               Father: XYZ
               Village · Phone                                  */
  #cust-tbl-card .tbl,
  #cust-tbl-card tbody { display: block; }
  #cust-tbl-card thead { display: none; }
  #cust-tbl-card tr.clickable-row {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    grid-template-areas:
      "img name    status"
      "img father  father"
      "img village phone";
    column-gap: 10px;
    row-gap: 2px;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--border);
  }
  #cust-tbl-card.select-mode tr.clickable-row {
    grid-template-columns: 28px 44px minmax(0, 1fr) auto;
    grid-template-areas:
      "check img name    status"
      "check img father  father"
      "check img village phone";
  }
  #cust-tbl-card tr.clickable-row > td {
    display: block;
    padding: 0;
    border: 0;
    white-space: normal;
    font-size: 0.82rem;
    color: var(--text2);
  }
  #cust-tbl-card tr.clickable-row > td[data-cell="select"] { grid-area: check; display: none; }
  #cust-tbl-card.select-mode tr.clickable-row > td[data-cell="select"] { display: block; }
  #cust-tbl-card td[data-cell="img"]       { grid-area: img; align-self: start; }
  #cust-tbl-card td[data-cell="name"]      { grid-area: name; font-size: 0.95rem; font-weight: 600; color: var(--text); }
  #cust-tbl-card td[data-cell="status"]    { grid-area: status; width: auto; }
  #cust-tbl-card td[data-cell="father"]    { grid-area: father; }
  #cust-tbl-card td[data-cell="father"] br { display: none; }
  #cust-tbl-card td[data-cell="father"] .f-lbl { display: inline; margin-right: 4px; }
  #cust-tbl-card td[data-cell="village"]   { grid-area: village; }
  #cust-tbl-card td[data-cell="phone"]     { grid-area: phone; text-align: right; }
  #cust-tbl-card tr.clickable-row > td[data-cell="aadhaar"],
  #cust-tbl-card tr.clickable-row > td[data-cell="guarantor"],
  #cust-tbl-card tr.clickable-row > td[data-cell="category"] { display: none; }
  /* Empty-state row */
  #cust-tbl-card tbody > tr:not(.clickable-row) { display: block; }
  #cust-tbl-card tbody > tr:not(.clickable-row) > td { display: block; }

  .tbl th, .tbl td { padding: 9px 10px; font-size: 0.84rem; }

  /* Modals: full screen, every field on its own line */
  .modal-dialog:not(.modal-sm) {
    max-width: none;
    width: 100%;
    height: 100%;
    margin: 0;
  }
  .modal-dialog:not(.modal-sm) .modal-content {
    height: 100%;
    border: 0 !important;
    border-radius: 0 !important;
  }
  .modal-dialog:not(.modal-sm) .modal-body { overflow-y: auto; }
  .modal-body .row > [class*="col-"] { flex: 0 0 100%; max-width: 100%; }
  .modal-body .row > [style*="border-left"] { border-left: 0 !important; border-top: 1px solid var(--border); padding-top: 16px; }
  .modal-footer { position: sticky; bottom: 0; background: var(--modal-bg); }

  /* Home hero */
  .hero-h1 { font-size: 2rem; }
  .hero-bg { width: 300px; height: 300px; }
  .hero-btns { flex-direction: column; align-items: stretch; padding: 0 16px; }
  .hero-features { gap: 12px 18px; }

  /* Floating WhatsApp button + toasts clear of the screen edge */
  .btn-fab { right: 16px; bottom: 16px; width: 52px; height: 52px; }
  .toast-wrap { left: 12px; right: 12px; transform: none; top: 62px; }
  .toast-item { max-width: 100%; }

  /* Camera overlay */
  .cam-overlay { padding: 12px; }
  .cam-overlay-video { width: 100%; max-width: 94vw; height: auto; max-height: 55vh; }
  .cam-overlay-actions { width: 100%; justify-content: center; }
}

/* Very small phones */
@media (max-width: 380px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .detail-card .dc-info { grid-template-columns: 1fr; }
  .sel-filter { flex-basis: 100%; }
}

/* Short laptop screens (e.g. 1366×768): keep modals usable */
@media (max-height: 800px) and (min-width: 768px) {
  .modal-dialog { margin-top: 12px; margin-bottom: 12px; }
  .cam-box-md { height: 100px; }
}
