
/* CraftGrid master screens - mobile presentation only.
   Desktop layout is intentionally left unchanged. */
@media (max-width: 767.98px) {
  .cg-master-mobile-polish .cg-master-page-head {
    display:flex !important;
    flex-direction:column !important;
    align-items:flex-start !important;
    gap:.55rem !important;
    margin-bottom:1rem !important;
  }
  .cg-master-mobile-polish .cg-master-page-head > div:first-child {
    width:100%;
    min-width:0;
  }
  .cg-master-mobile-polish .cg-master-page-head small.text-muted,
  .cg-master-mobile-polish .cg-master-page-head .cg-master-description {
    display:none !important;
  }
  .cg-master-mobile-polish .cg-master-page-head h2 {
    font-size:1.55rem;
    line-height:1.18;
    margin:0 !important;
  }
  .cg-master-mobile-polish .cg-master-page-head .cg-master-new-btn {
    display:inline-block;
    margin-top:.55rem;
    white-space:normal;
    max-width:100%;
  }

  /* Stack filter controls naturally; keep action buttons readable. */
  .cg-master-mobile-polish form .row > [class*="col-"] {
    width:100%;
  }
  .cg-master-mobile-polish form .row > [class*="col-"].d-flex {
    justify-content:flex-start;
    align-items:stretch !important;
    flex-wrap:wrap;
  }
  .cg-master-mobile-polish form .row > [class*="col-"].d-flex .btn {
    min-height:40px;
  }

  /* Existing master tables become readable cards on phones. */
  .cg-master-mobile-polish .cg-master-desktop-table {
    overflow:visible !important;
  }
  .cg-master-mobile-polish .cg-master-desktop-table table {
    display:block;
    width:100%;
  }
  .cg-master-mobile-polish .cg-master-desktop-table thead {
    display:none;
  }
  .cg-master-mobile-polish .cg-master-desktop-table tbody,
  .cg-master-mobile-polish .cg-master-desktop-table tbody tr {
    display:block;
    width:100%;
  }
  .cg-master-mobile-polish .cg-master-desktop-table tbody tr {
    margin:0;
    padding:12px 14px;
    border-bottom:1px solid #e7eeee;
  }
  .cg-master-mobile-polish .cg-master-desktop-table tbody tr:last-child {
    border-bottom:0;
  }
  .cg-master-mobile-polish .cg-master-desktop-table tbody td {
    display:flex;
    align-items:flex-start;
    justify-content:space-between;
    gap:12px;
    width:100%;
    min-width:0;
    padding:7px 0 !important;
    border:0 !important;
    text-align:right !important;
    white-space:normal !important;
    overflow-wrap:anywhere;
  }
  .cg-master-mobile-polish .cg-master-desktop-table tbody td::before {
    flex:0 0 38%;
    text-align:left;
    font-size:.68rem;
    line-height:1.25;
    font-weight:700;
    color:#637786;
    text-transform:uppercase;
    letter-spacing:.035em;
  }
  .cg-master-mobile-polish .cg-master-desktop-table tbody td:nth-child(1)::before { content:"Code"; }
  .cg-master-mobile-polish .cg-master-desktop-table tbody td:nth-child(2)::before { content:"Name"; }
  .cg-master-mobile-polish .cg-master-desktop-table tbody td:last-child::before { content:"Actions"; }

  .cg-master-mobile-polish .cg-master-desktop-table tbody td.text-end,
  .cg-master-mobile-polish .cg-master-desktop-table tbody td.text-center {
    justify-content:space-between;
  }
  .cg-master-mobile-polish .cg-master-desktop-table tbody td:last-child {
    padding-top:10px !important;
    margin-top:4px;
    border-top:1px solid #eef2f0 !important;
    text-align:left !important;
  }
  .cg-master-mobile-polish .cg-master-desktop-table tbody td:last-child::before {
    align-self:center;
  }
  .cg-master-mobile-polish .cg-master-desktop-table tbody td:last-child > * {
    margin-left:auto;
  }
  .cg-master-mobile-polish .cg-master-desktop-table tbody td[colspan] {
    display:block;
    text-align:center !important;
    padding:26px 10px !important;
  }
  .cg-master-mobile-polish .cg-master-desktop-table tbody td[colspan]::before {
    display:none;
  }
  .cg-master-mobile-polish .cg-master-desktop-table tbody td form.d-inline {
    display:inline-flex !important;
  }
  .cg-master-mobile-polish .cg-master-desktop-table tbody td .btn {
    min-height:38px;
  }

  /* Column labels for the individual master tables. */
  .cg-master-countries .cg-master-desktop-table tbody td:nth-child(3)::before { content:"Currency"; }
  .cg-master-countries .cg-master-desktop-table tbody td:nth-child(4)::before { content:"Status"; }

  .cg-master-states .cg-master-desktop-table tbody td:nth-child(3)::before { content:"Country"; }
  .cg-master-states .cg-master-desktop-table tbody td:nth-child(4)::before { content:"Status"; }

  .cg-master-cities .cg-master-desktop-table tbody td:nth-child(3)::before { content:"State"; }
  .cg-master-cities .cg-master-desktop-table tbody td:nth-child(4)::before { content:"Status"; }

  .cg-master-companies .cg-master-desktop-table tbody td:nth-child(3)::before { content:"Country"; }
  .cg-master-companies .cg-master-desktop-table tbody td:nth-child(4)::before { content:"Description"; }
  .cg-master-companies .cg-master-desktop-table tbody td:nth-child(5)::before { content:"Status"; }

  .cg-master-businesspartners .cg-master-desktop-table tbody td:nth-child(3)::before { content:"Type"; }
  .cg-master-businesspartners .cg-master-desktop-table tbody td:nth-child(4)::before { content:"Company"; }
  .cg-master-businesspartners .cg-master-desktop-table tbody td:nth-child(5)::before { content:"City"; }
  .cg-master-businesspartners .cg-master-desktop-table tbody td:nth-child(6)::before { content:"Status"; }

  .cg-master-productcategories .cg-master-desktop-table tbody td:nth-child(3)::before { content:"Company"; }
  .cg-master-productcategories .cg-master-desktop-table tbody td:nth-child(4)::before { content:"Description"; }
  .cg-master-productcategories .cg-master-desktop-table tbody td:nth-child(5)::before { content:"Status"; }

  .cg-master-unitofmeasures .cg-master-desktop-table tbody td:nth-child(3)::before { content:"Company"; }
  .cg-master-unitofmeasures .cg-master-desktop-table tbody td:nth-child(4)::before { content:"Description"; }
  .cg-master-unitofmeasures .cg-master-desktop-table tbody td:nth-child(5)::before { content:"Status"; }

  .cg-master-brands .cg-master-desktop-table tbody td:nth-child(3)::before { content:"Company"; }
  .cg-master-brands .cg-master-desktop-table tbody td:nth-child(4)::before { content:"Description"; }
  .cg-master-brands .cg-master-desktop-table tbody td:nth-child(5)::before { content:"Status"; }

  .cg-master-warehouses .cg-master-desktop-table tbody td:nth-child(3)::before { content:"Company"; }
  .cg-master-warehouses .cg-master-desktop-table tbody td:nth-child(4)::before { content:"Description"; }
  .cg-master-warehouses .cg-master-desktop-table tbody td:nth-child(5)::before { content:"Status"; }


  .cg-master-currencies .cg-master-desktop-table tbody td:nth-child(3)::before { content:"Symbol"; }
  .cg-master-currencies .cg-master-desktop-table tbody td:nth-child(4)::before { content:"Decimals"; }
  .cg-master-currencies .cg-master-desktop-table tbody td:nth-child(5)::before { content:"Base"; }
  .cg-master-currencies .cg-master-desktop-table tbody td:nth-child(6)::before { content:"Status"; }

  .cg-master-items .cg-master-desktop-table tbody td:nth-child(3)::before { content:"Category"; }
  .cg-master-items .cg-master-desktop-table tbody td:nth-child(4)::before { content:"UOM"; }
  .cg-master-items .cg-master-desktop-table tbody td:nth-child(5)::before { content:"Brand"; }
  .cg-master-items .cg-master-desktop-table tbody td:nth-child(6)::before { content:"Type"; }
  .cg-master-items .cg-master-desktop-table tbody td:nth-child(7)::before { content:"Tracking"; }
  .cg-master-items .cg-master-desktop-table tbody td:nth-child(8)::before { content:"Base Selling Price"; }
  .cg-master-items .cg-master-desktop-table tbody td:nth-child(9)::before { content:"MRP"; }
  .cg-master-items .cg-master-desktop-table tbody td:nth-child(10)::before { content:"Status"; }


  .cg-master-assetcategories .cg-master-desktop-table tbody td:nth-child(3)::before { content:"Company"; }
  .cg-master-assetcategories .cg-master-desktop-table tbody td:nth-child(4)::before { content:"Description"; }
  .cg-master-assetcategories .cg-master-desktop-table tbody td:nth-child(5)::before { content:"Status"; }

  /* Branches/Departments already have purpose-built mobile cards. */
  .cg-master-branches .cg-mobile-cards,
  .cg-master-departments .cg-mobile-cards {
    display:block;
  }


  /* Posting Profile account-mapping rows: turn the wide desktop table into
     compact, readable cards on phones. Desktop remains unchanged. */
  .posting-profile-form .table-responsive {
    overflow-x:visible;
  }
  .posting-profile-form #linesTable {
    display:block;
    width:100%;
    margin-bottom:0;
  }
  .posting-profile-form #linesTable thead {
    display:none;
  }
  .posting-profile-form #linesTable tbody,
  .posting-profile-form #linesTable tbody tr {
    display:block;
    width:100%;
  }
  .posting-profile-form #linesTable tbody tr.posting-line {
    margin:0 0 12px;
    padding:10px 12px;
    border:1px solid #dfe7e5;
    border-radius:12px;
    background:#fff;
    box-shadow:0 1px 3px rgba(0,0,0,.05);
  }
  .posting-profile-form #linesTable tbody td {
    display:grid;
    grid-template-columns:minmax(96px,34%) minmax(0,1fr);
    align-items:center;
    gap:10px;
    width:100%;
    min-width:0;
    padding:7px 0 !important;
    border:0 !important;
    text-align:left !important;
    white-space:normal !important;
    overflow:visible;
  }
  .posting-profile-form #linesTable tbody td::before {
    content:attr(data-label);
    min-width:0;
    font-size:.7rem;
    line-height:1.25;
    font-weight:700;
    color:#637786;
    text-transform:uppercase;
    letter-spacing:.025em;
  }
  .posting-profile-form #linesTable tbody td > .form-select,
  .posting-profile-form #linesTable tbody td > .form-control,
  .posting-profile-form #linesTable tbody td > .form-check {
    width:100%;
    min-width:0;
    margin:0;
  }
  .posting-profile-form #linesTable tbody td:first-child {
    padding-top:2px !important;
  }
  .posting-profile-form #linesTable tbody td:first-child .line-number {
    font-weight:800;
    color:#173f63;
  }
  .posting-profile-form #linesTable .form-check {
    display:flex;
    align-items:center;
    gap:8px;
  }
  .posting-profile-form #linesTable .form-check-input {
    flex:0 0 auto;
    margin:0;
  }
  .posting-profile-form #linesTable tbody td[data-label="Actions"] {
    display:flex;
    justify-content:flex-end;
    padding-top:10px !important;
    margin-top:4px;
    border-top:1px solid #eef2f0 !important;
  }
  .posting-profile-form #linesTable tbody td[data-label="Actions"]::before {
    display:none;
  }
  .posting-profile-form #linesTable .remove-line {
    min-width:42px;
    min-height:38px;
  }
  .posting-profile-form .alert {
    font-size:.9rem;
  }
}


/* ============================================================
   Posting Profile Details - desktop action alignment
   Presentation only. No accounting/business logic changes.
   ============================================================ */
.cg-posting-profile-details-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.cg-posting-profile-details-title {
    min-width: 0;
    flex: 1 1 auto;
}

.cg-posting-profile-details-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .55rem;
    flex: 0 0 auto;
    flex-wrap: wrap;
}

.cg-posting-profile-details-actions > form {
    display: inline-flex;
    align-items: center;
    margin: 0;
}

.cg-posting-profile-details-actions > .btn,
.cg-posting-profile-details-actions > form > .btn,
.cg-posting-profile-details-actions > form > button {
    margin: 0 !important;
    white-space: nowrap;
}

/* ============================================================
   Posting Profile Details - mobile polish
   Presentation only. No accounting/business logic changes.
   ============================================================ */
@media (max-width: 767.98px) {
    .cg-posting-profile-details {
        width: 100%;
        min-width: 0;
    }

    .cg-posting-profile-details-header {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: .75rem;
        margin-bottom: 1rem;
    }

    .cg-posting-profile-details-title {
        min-width: 0;
    }

    .cg-posting-profile-details-title h2 {
        font-size: 1.45rem;
        line-height: 1.18;
        overflow-wrap: anywhere;
        word-break: break-word;
        margin-bottom: .2rem !important;
    }

    .cg-posting-profile-details-title small {
        display: block;
        line-height: 1.35;
    }

    .cg-posting-profile-details-actions {
        width: 100%;
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: .55rem;
    }

    .cg-posting-profile-details-actions > form {
        display: contents;
    }

    .cg-posting-profile-details-actions > .btn,
    .cg-posting-profile-details-actions > form > .btn,
    .cg-posting-profile-details-actions > form > button {
        width: 100%;
        min-width: 0;
        min-height: 44px;
        margin: 0 !important;
        white-space: nowrap;
    }

    .cg-posting-profile-details .card-body {
        padding: 1rem;
    }

    .cg-posting-profile-details .card-body dl.row {
        margin: 0;
    }

    .cg-posting-profile-details .card-body dl.row dt,
    .cg-posting-profile-details .card-body dl.row dd {
        width: 100%;
        margin-left: 0;
        padding-left: 0;
        padding-right: 0;
    }

    .cg-posting-profile-details .card-body dl.row dt {
        margin-top: .55rem;
        margin-bottom: .15rem;
    }

    .cg-posting-profile-details .card-body dl.row dt:first-child {
        margin-top: 0;
    }

    .cg-posting-profile-details .card-body dl.row dd {
        margin-bottom: .55rem;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    .cg-posting-profile-mapping-card .card-header {
        padding: .85rem 1rem;
    }

    .cg-posting-profile-mapping-card .table-responsive {
        overflow: visible;
    }

    .cg-posting-profile-mapping-table,
    .cg-posting-profile-mapping-table tbody,
    .cg-posting-profile-mapping-table tr {
        display: block;
        width: 100%;
    }

    .cg-posting-profile-mapping-table thead {
        display: none;
    }

    .cg-posting-profile-mapping-table tbody tr {
        padding: .75rem 1rem;
        border-bottom: 1px solid #e7eeeb;
    }

    .cg-posting-profile-mapping-table tbody tr:last-child {
        border-bottom: 0;
    }

    .cg-posting-profile-mapping-table tbody td {
        display: grid;
        grid-template-columns: minmax(92px, 34%) minmax(0, 1fr);
        gap: .6rem;
        align-items: start;
        width: 100%;
        min-width: 0;
        padding: .4rem 0 !important;
        border: 0 !important;
        text-align: left !important;
        white-space: normal !important;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    .cg-posting-profile-mapping-table tbody td::before {
        content: attr(data-label);
        font-size: .7rem;
        line-height: 1.3;
        font-weight: 700;
        color: #637786;
        text-transform: uppercase;
        letter-spacing: .025em;
    }

    .cg-posting-profile-mapping-table tbody td:first-child {
        padding-top: 0 !important;
    }

    .cg-posting-profile-mapping-table tbody td:first-child::before {
        color: #173f63;
    }

    .cg-posting-profile-details-back {
        width: 100%;
    }

    .cg-posting-profile-details-back .cg-back-btn {
        width: 100%;
        min-height: 44px;
    }
}

@media (max-width: 359.98px) {
    .cg-posting-profile-details-actions {
        grid-template-columns: 1fr;
    }
}


/* ============================================================
   Chart of Accounts - mobile tree polish
   Presentation only. No accounting/business logic changes.
   Desktop layout remains unchanged.
   ============================================================ */
@media (max-width: 767.98px) {
  .cg-coa-page .craftgrid-coa-table {
    display:block;
    width:100%;
    border-collapse:separate;
    border-spacing:0;
    background:transparent;
  }

  .cg-coa-page .craftgrid-coa-table thead {
    display:none;
  }

  .cg-coa-page .craftgrid-coa-table tbody,
  .cg-coa-page .craftgrid-coa-table tbody tr {
    display:block;
    width:100%;
  }

  .cg-coa-page .craftgrid-coa-table tbody tr {
    position:relative;
    margin:0 0 .65rem;
    padding:.78rem .85rem .7rem;
    border:1px solid #dfe8e5;
    border-radius:14px;
    background:#fff;
    box-shadow:0 2px 8px rgba(18, 54, 73, .06);
  }

  .cg-coa-page .craftgrid-coa-table tbody td {
    border:0 !important;
    padding:.18rem 0 !important;
    min-width:0;
    white-space:normal !important;
  }

  /* Code + account name form the primary mobile row. */
  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(1) {
    display:inline-block;
    width:28%;
    vertical-align:top;
    color:#536a7a;
    font-size:.78rem;
    font-weight:800;
    padding-top:.35rem !important;
  }

  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(2) {
    display:inline-block;
    width:72%;
    vertical-align:top;
  }

  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(2) .craftgrid-coa-account {
    min-width:0;
    padding-left:calc(var(--coa-depth) * .8rem);
    gap:.35rem;
    align-items:flex-start;
  }

  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(2) .craftgrid-coa-branch {
    color:#80919e;
    line-height:1.45;
  }

  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(2) span:last-child {
    line-height:1.35;
    overflow-wrap:anywhere;
  }

  /* Secondary account metadata stays available without dominating the tree. */
  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(3),
  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(4),
  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(5),
  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(6) {
    display:flex;
    justify-content:space-between;
    gap:.75rem;
    align-items:center;
    margin-top:.18rem;
    padding-top:.28rem !important;
    border-top:1px solid #f0f3f2 !important;
    color:#607482;
    font-size:.78rem;
  }

  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(3)::before { content:"Company"; }
  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(4)::before { content:"Type"; }
  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(5)::before { content:"Balance"; }
  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(6)::before { content:"Classification"; }

  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(3)::before,
  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(4)::before,
  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(5)::before,
  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(6)::before {
    flex:0 0 auto;
    color:#82919b;
    font-size:.66rem;
    font-weight:800;
    letter-spacing:.04em;
    text-transform:uppercase;
  }

  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(7),
  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(8) {
    display:inline-flex;
    width:auto;
    margin:.35rem .4rem 0 0;
    padding:0 !important;
  }

  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(9) {
    display:flex;
    align-items:center;
    justify-content:flex-end;
    gap:.4rem;
    margin-top:.65rem;
    padding-top:.65rem !important;
    border-top:1px solid #e9efed !important;
  }

  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(9)::before {
    content:"";
  }

  .cg-coa-page .craftgrid-coa-table tbody td:nth-child(9) .btn {
    min-height:38px;
  }

  .cg-coa-page .craftgrid-coa-table tbody td[colspan] {
    display:block !important;
    width:100% !important;
    text-align:center !important;
    padding:1.5rem .5rem !important;
  }
}

/* ============================================================
   Finance & Accounting - left navigation polish
   Keeps the agreed Masters / Transactions / Reports / Period Management structure.
   Presentation only. No permissions or routing changes.
   ============================================================ */
@media (max-width: 767.98px) {
  .erp-sidebar .sidebar-group[data-cg-module="accounts"] > .sidebar-group-toggle {
    margin:.3rem .45rem .5rem;
    min-height:48px;
    padding:.72rem .82rem;
    border:1px solid rgba(143,169,198,.18);
    background:rgba(255,255,255,.045);
  }

  .erp-sidebar .sidebar-group[data-cg-module="accounts"] > .sidebar-submenu {
    padding-left:.35rem;
    padding-right:.35rem;
  }

  .erp-sidebar .sidebar-group[data-cg-module="accounts"] .sidebar-subsection-label {
    margin:.55rem .25rem .3rem;
    padding:.46rem .65rem;
    min-height:34px;
    display:flex;
    align-items:center;
    color:#eef5fb;
    background:rgba(143,169,198,.16);
    border-left-width:3px;
    font-size:.69rem;
    letter-spacing:.09em;
  }

  .erp-sidebar .sidebar-group[data-cg-module="accounts"] .sidebar-submenu-link {
    min-height:43px;
    margin-left:.2rem;
    margin-right:.2rem;
    padding:.58rem .7rem .58rem .8rem;
    border-radius:8px;
  }
}
