/* MunimIQ — phone layout (≤760px / ≤900px). Loaded after app.css + live.css; desktop and print untouched. */

/* ---------- app feel on touch screens ---------- */
@media (max-width: 900px) {
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { -webkit-tap-highlight-color: transparent; overflow-x: hidden; }
  a, button, .btn, label, select, summary, [role=button] { touch-action: manipulation; }
  img, svg, video, canvas { max-width: 100%; }
  .main { overflow-x: clip; min-width: 0; }
  #view { min-width: 0; }

  /* one-line header: company · sync dot · theme · avatar (language is in the avatar menu) */
  .top { flex-wrap: nowrap; gap: 8px; position: sticky; top: 0; z-index: 40; margin: -16px -14px 0; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent); -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid var(--line); }
  .top .mob-co { flex: 1 1 auto; max-width: none; min-width: 0; }
  .top .mob-co .co-btn { padding: 5px 10px 5px 6px; gap: 8px; }
  .top .mob-co .co-btn .nm b { font-size: 13.5px; }
  .top-r { flex-wrap: nowrap; gap: 6px; flex: 0 0 auto; }
  .top-r .icon-btn { width: 38px; height: 38px; border-radius: 12px; }
  .top-r #lng { display: none; }
  .top-r .user-btn .av { width: 38px; height: 38px; }
  .top .tchip { width: 38px; height: 38px; padding: 0; justify-content: center; border-radius: 12px; }
  .top .tchip .tx { display: none; }
  .top .tchip .d { margin: 0; }
  .top .menu { max-width: calc(100vw - 28px); }

  /* page head */
  .page-h, .ph { gap: 10px; }
  .h1 { font-size: 26px; line-height: 1.12; letter-spacing: -.02em; overflow-wrap: anywhere; }

  /* inputs ≥16px: phones (iOS) stop zooming the page on focus */
  input:not([type=checkbox]):not([type=radio]):not([type=range]), select, textarea, input.inp, select.inp, .ask-bar input, .search input { font-size: 16px; }
  input.inp, select.inp { height: 44px; }

  /* tap targets */
  .btn { min-height: 40px; }
  .seg button, .seg a, .tabs button, .tabs a { min-height: 36px; }

  /* modals → bottom sheets; drawers → full screen */
  .overlay:not(.drawer-ov) { align-items: flex-end; padding: 0; }
  .overlay:not(.drawer-ov) > .modal { width: 100%; max-width: 100%; max-height: 92vh; max-height: 92dvh; border-radius: 22px 22px 0 0; border-bottom: 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); animation: mc-up .22s ease; }
  .overlay:not(.drawer-ov) > .modal::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line2); margin: -6px auto 12px; }
  .drawer { width: 100%; border-left: 0; padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); }
  .msheet-in { max-height: 88dvh; }

  /* toasts + help button stay clear of the bottom bar */
  .hp-fab { height: 44px; width: 44px; padding: 0; justify-content: center; }
  .hp-fab { font-size: 0; gap: 0; }
  .hp-fab > :not(.dot) { display: none; }
  .bnav { padding-bottom: 6px; }
  .bnav a { min-width: 0; }
}
@keyframes mc-up { from { transform: translateY(40px); opacity: .4; } }

/* ---------- tables that would scroll sideways → cards ---------- */
@media screen and (max-width: 760px) {
  /* small tables: wrap instead of scroll */
  table.mc-fit th, table.mc-fit td { white-space: normal; padding-left: 8px; padding-right: 8px; overflow-wrap: break-word; word-break: normal; }
  table.mc-fit td.r, table.mc-fit th.r { white-space: nowrap; overflow-wrap: normal; }
  table.mc-fit td:first-child, table.mc-fit th:first-child { padding-left: 2px; }
  table.mc-fit td:last-child, table.mc-fit th:last-child { padding-right: 2px; }
  table.mc-fit { font-size: 12.5px; }

  .tbl-wrap:has(> table.mc) { overflow: visible; }
  table.mc, table.mc > tbody, table.mc > tfoot { display: block; width: 100%; }
  table.mc > thead, table.mc tr.mc-hr { display: none; }
  table.mc > tbody > tr, table.mc > tfoot > tr {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 14px; align-items: start;
    margin: 0 0 10px; padding: 12px 14px; border-radius: 16px;
    background: var(--card2); border: 1px solid var(--line); position: relative;
  }
  .card table.mc > tbody > tr, .card table.mc > tfoot > tr { background: rgba(var(--ov), .035); }
  table.mc > tbody > tr:last-child { margin-bottom: 0; }
  table.mc > tbody > tr:hover > td { background: none; }
  table.mc tr.click { cursor: pointer; }
  table.mc tr.click:active { transform: scale(.99); border-color: var(--line2); }

  table.mc td { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; padding: 0; border: 0; white-space: normal; overflow-wrap: anywhere; text-align: left; font-size: 13.5px; line-height: 1.35; background: none !important; }
  table.mc td::before { content: attr(data-l); font-family: 'Geist', sans-serif; font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--t4); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  table.mc td:not([data-l])::before, table.mc td[data-l=""]::before { display: none; }
  table.mc td.r { font-family: 'Geist Mono', monospace; font-size: 13px; }
  table.mc td.r:not(.mc-r):not(.mc-a) { text-align: left; align-items: flex-start; }
  table.mc td.mc-r { align-items: flex-end; text-align: right; }
  table.mc td.mc-e { display: none; }
  table.mc td > * { max-width: 100%; }

  /* title row: name left, main amount right */
  table.mc td.mc-t { grid-column: 1 / 2; grid-row: 1; font-weight: 650; font-size: 14.5px; color: var(--text); padding-right: 4px; }
  table.mc td.mc-t::before { display: none; }
  table.mc td.mc-t, table.mc td.mc-t.r { font-family: 'Geist', sans-serif; font-size: 14.5px; text-align: left; align-items: flex-start; }
  table.mc td.mc-t:only-child, table.mc tr.mc-solo td.mc-t:not(:has(~ .mc-a)) { grid-column: 1 / -1; }
  table.mc td.mc-a { grid-column: 2 / 3; grid-row: 1; align-items: flex-end; text-align: right; font-family: 'Geist Mono', monospace; font-weight: 700; font-size: 15px; color: var(--text); white-space: nowrap; }
  table.mc td.mc-a::before { display: none; }
  table.mc tr:not(:has(> .mc-a)) > td.mc-t { grid-column: 1 / -1; }
  table.mc tr > td.mc-t ~ td:not(.mc-a):not(.mc-act):not(.mc-e) { grid-row: auto; }
  /* a thin line under the title row when details follow */
  table.mc tr:not(.mc-solo):not(.mc-full) > td.mc-t { padding-bottom: 8px; border-bottom: 1px dashed var(--line); }
  table.mc tr:not(.mc-solo):not(.mc-full) > td.mc-a { padding-bottom: 8px; border-bottom: 1px dashed var(--line); align-self: stretch; }

  /* keep colour cues of the row (Dr/Cr, overdue …) */
  table.mc tr.f-g > td:last-child { color: var(--mint); }
  table.mc tr.f-r > td:last-child { color: var(--coral); }

  /* actions row */
  table.mc td.mc-act { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; padding-top: 2px; }
  table.mc td.mc-act::before { display: none; }
  table.mc td.mc-act:has(> input[type=checkbox]:only-child) { position: absolute; top: 12px; right: 12px; width: auto; padding: 0; }
  table.mc tr:has(> td.mc-act > input[type=checkbox]:only-child) { padding-right: 44px; }
  table.mc td.mc-act .btn, table.mc td.mc-act button { min-height: 38px; }
  table.mc td.mc-act + td.mc-act { padding-top: 0; }

  /* full-width rows (group headings, notes, totals spanning the table) */
  table.mc tr.mc-full { display: block; padding: 10px 14px; }
  table.mc tr.mc-full > td { display: block; }
  table.mc tr.mc-full > td::before { display: none; }

  /* totals */
  table.mc tr.mc-sum { background: rgba(var(--lime-rgb), .07); border-color: rgba(var(--lime-rgb), .35); }
  table.mc tr.mc-sum td { font-weight: 700; }

  /* editable grids (inputs in cells): label above each field */
  table.mc.mc-form td.mc-in { grid-column: 1 / -1; }
  table.mc.mc-form td.mc-in:has(input[type=number]:only-child), table.mc.mc-form td.mc-in:has(input[inputmode=decimal]:only-child) { grid-column: span 1; }
  table.mc.mc-form td.mc-in input, table.mc.mc-form td.mc-in select, table.mc.mc-form td.mc-in textarea { width: 100% !important; max-width: 100%; min-width: 0 !important; box-sizing: border-box; }
  table.mc.mc-form td.mc-in > * { max-width: 100%; }
  table.mc.mc-form td.mc-in.mc-r { align-items: stretch; text-align: left; }

  /* many-column tables: 2 columns of details is still easier to read */
  table.mc[data-mcn="2"] > tbody > tr, table.mc[data-mcn="3"] > tbody > tr { grid-template-columns: minmax(0, 1fr) auto; }
}
@media screen and (max-width: 360px) {
  table.mc > tbody > tr, table.mc > tfoot > tr { padding: 11px 12px; gap: 7px 10px; }
  table.mc td.mc-a { font-size: 14px; }
}

/* ---------- voucher item lines on small phones: item + ✕ / qty · rate / disc · GST ---------- */
@media (max-width: 480px) {
  .lv-iline, .lv-iline:not(:has(> select)) { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px; padding-bottom: 10px; border-bottom: 1px dashed var(--line); }
  .lv-iline > .lv-pick { grid-column: 1 / 3; grid-row: 1; }
  .lv-iline > [data-rm] { grid-column: 3; grid-row: 1; width: 44px !important; height: 44px !important; }
  .lv-iline > [data-k=qty], .lv-iline > [data-k=disc] { grid-column: 1; }
  .lv-iline > [data-k=rate], .lv-iline > [data-k=gstRate] { grid-column: 2; }
  .lv-iline > select[data-k=godown] { grid-column: 1 / 3; }
  .lv-iline > .lv-iextra { grid-column: 1 / -1; }
}
/* month / date pickers: keep the calendar icon off the text */
@media (max-width: 760px) {
  input[type=month], input[type=date] { min-width: 0; max-width: 100%; }
  input.inp[type=month], input.inp[type=date] { padding-right: 8px; }
}

/* ---------- admin panel (/admin) on phones: compact sticky header + bottom bar ---------- */
@media (max-width: 760px) {
  #app.tp .tp-top { flex-wrap: nowrap; overflow: visible; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; }
  #app.tp .tp-top > div { flex: 1 1 auto; min-width: 0; line-height: 1.2; }
  #app.tp .tp-top b { font-size: 17px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #app.tp .tp-top small { display: block; font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #app.tp .tp-top br { display: none; }
  #app.tp .tp-top .logo-mark { flex: none; }
  body.mm-tp #app.tp .tp-top .btn[href="/app"] { display: none; }
  body.mm-tp #app.tp .tp-nav { display: none; }
  body.mm-tp #app.tp .tp-wrap { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
  #app.tp .tp-head > div:last-child { text-align: left !important; }
  #app.tp .tp-head a.muted:first-child, #app.tp .tp-back { display: inline-flex; align-items: center; min-height: 36px; padding: 0 12px 0 0; font-size: 13.5px !important; font-weight: 600; }
  #app.tp .tp-h1 { font-size: 22px; overflow-wrap: anywhere; }
  #app.tp .tp-kpi { min-width: 0; }
  #app.tp .tp-kpi b { overflow-wrap: anywhere; }
  /* "give a plan" and other admin popups → bottom sheet */
  .gp-ov { align-items: flex-end; padding: 0; }
  .gp-ov > .gp { max-width: 100%; max-height: 92dvh; overflow-y: auto; border-radius: 22px 22px 0 0; padding-bottom: env(safe-area-inset-bottom); animation: mc-up .22s ease; }

  .mm-bnav { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; position: fixed; z-index: 60; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); padding: 6px; border-radius: 22px; background: var(--card2); border: 1px solid var(--line2); box-shadow: var(--shadow, 0 10px 30px rgba(0,0,0,.35)); }
  .mm-bnav a { height: 50px; border-radius: 16px; color: var(--t2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; font-weight: 600; text-decoration: none; min-width: 0; touch-action: manipulation; }
  .mm-bnav a span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mm-bnav a.on { background: var(--lime); color: var(--on-lime); }
  .mm-sheet .msheet-g a.on { border-color: var(--lime); }
}
@media (min-width: 761px) { .mm-bnav, .mm-sheet { display: none !important; } }
@media print { .mm-bnav, .mm-sheet { display: none !important; } }
