/*
 * DATAWISE Application Layout System
 * Version: 1.0.0-dev3
 *
 * Purpose:
 * - constrain small/medium ERP screens on ultra-wide monitors
 * - keep DWGrid fluid inside its parent
 * - support 1/2, 1/3 + 2/3, 1/4 + 3/4 page layouts
 * - remain independent from DWGrid core CSS
 * - avoid Bootstrap .container/.row/.col naming collisions
 *
 * Usage:
 *   <div class="dw-app-layout dw-app-layout--normal">
 *       ...
 *   </div>
 *
 * Width presets:
 *   --compact : 1180px
 *   --normal  : 1480px
 *   --wide    : 1760px
 *   --xwide   : 2080px
 *   --fluid   : no max-width
 */


/* =========================================================
   DESIGN TOKENS
   ========================================================= */

:root {
    --dw-layout-gutter: 16px;
    --dw-layout-gap: 16px;

    --dw-layout-compact: 1180px;
    --dw-layout-normal: 1480px;
    --dw-layout-wide: 1760px;
    --dw-layout-xwide: 2080px;

    --dw-layout-panel-bg: #ffffff;
    --dw-layout-panel-border: #e2e6e9;
    --dw-layout-panel-radius: 7px;
}


/* =========================================================
   PAGE / WORKSPACE WIDTH
   ========================================================= */

.dw-app-layout {
    width: calc(100% - (var(--dw-layout-gutter) * 2));
    max-width: var(--dw-layout-normal);

    margin-left: auto;
    margin-right: auto;

    box-sizing: border-box;
}

.dw-app-layout--compact {
    max-width: var(--dw-layout-compact);
}

.dw-app-layout--normal {
    max-width: var(--dw-layout-normal);
}

.dw-app-layout--wide {
    max-width: var(--dw-layout-wide);
}

.dw-app-layout--xwide {
    max-width: var(--dw-layout-xwide);
}

.dw-app-layout--fluid {
    max-width: none;
}


/*
 * Optional left-aligned workspace.
 *
 * Useful in screens where the application's visual language is intentionally
 * left anchored instead of centered.
 */
.dw-app-layout--left {
    margin-left: var(--dw-layout-gutter);
    margin-right: auto;
}


/* =========================================================
   PAGE BLOCKS
   ========================================================= */

.dw-layout-section {
    width: 100%;
    min-width: 0;

    margin-bottom: 16px;

    box-sizing: border-box;
}

.dw-layout-section:last-child {
    margin-bottom: 0;
}


/* =========================================================
   FLEX GRID
   ========================================================= */

.dw-layout-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;

    margin-left: calc(var(--dw-layout-gap) / -2);
    margin-right: calc(var(--dw-layout-gap) / -2);

    box-sizing: border-box;
}

.dw-layout-col {
    width: 100%;
    min-width: 0;

    padding-left: calc(var(--dw-layout-gap) / 2);
    padding-right: calc(var(--dw-layout-gap) / 2);

    box-sizing: border-box;
}

.dw-layout-col--1-2 {
    flex: 0 0 50%;
    max-width: 50%;
}

.dw-layout-col--1-3 {
    flex: 0 0 33.333333%;
    max-width: 33.333333%;
}

.dw-layout-col--2-3 {
    flex: 0 0 66.666667%;
    max-width: 66.666667%;
}

.dw-layout-col--1-4 {
    flex: 0 0 25%;
    max-width: 25%;
}

.dw-layout-col--3-4 {
    flex: 0 0 75%;
    max-width: 75%;
}


/* =========================================================
   PANEL
   ========================================================= */

.dw-layout-panel {
    width: 100%;
    min-width: 0;

    background: var(--dw-layout-panel-bg);

    border: 1px solid var(--dw-layout-panel-border);
    border-radius: var(--dw-layout-panel-radius);

    box-sizing: border-box;
}

.dw-layout-panel--plain {
    border: 0;
    border-radius: 0;
    background: transparent;
}

.dw-layout-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;

    min-height: 38px;

    padding: 8px 10px;

    border-bottom: 1px solid #edf0f2;

    box-sizing: border-box;
}

.dw-layout-panel-title {
    margin: 0;

    color: #39434c;

    font-size: 13px;
    line-height: 20px;
    font-weight: 600;
}

.dw-layout-panel-actions {
    display: flex;
    align-items: center;
    gap: 6px;

    min-width: 0;
}

.dw-layout-panel-body {
    min-width: 0;

    padding: 10px;

    box-sizing: border-box;
}

.dw-layout-panel--grid .dw-layout-panel-body {
    padding: 0;
}


/* =========================================================
   GRID ACTION / TOOLS BAR
   ========================================================= */

/*
 * Preferred pattern when a page has its own actions AND DWGrid Tools.
 *
 * Left  : page-level actions
 * Right : DWGrid Tools
 *
 * This uses the horizontal space efficiently and keeps page actions away
 * from the Grid's own tools.
 */
.dw-layout-grid-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;

    width: 100%;
    min-width: 0;
    min-height: 30px;

    margin-bottom: 4px;

    box-sizing: border-box;
}

.dw-layout-grid-actions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 6px;

    min-width: 0;
}


/*
 * Inside a layout grid bar, DWGrid Tools stop using the core zero-height /
 * absolute positioning technique and become a normal flex item.
 *
 * This is only a layout override. DWGrid core remains unchanged.
 */
.dw-layout-grid-bar > .dw-grid-tools {
    position: relative;

    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    height: auto;

    margin: 0;
    padding: 0;

    z-index: 20;
}

.dw-layout-grid-bar > .dw-grid-tools .dw-grid-tools-inner {
    position: static;

    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;

    width: 100%;

    white-space: nowrap;
}


/* =========================================================
   DWGRID HOST
   ========================================================= */

/*
 * The Grid itself remains a fluid component.
 * The application layout decides how much horizontal space it receives.
 */
.dw-grid-host {
    width: 100%;
    min-width: 0;

    box-sizing: border-box;
}

.dw-grid-host .gridcontainer,
.dw-grid-host .grid,
.dw-grid-host .dw-grid-tools {
    max-width: 100%;
    min-width: 0;

    box-sizing: border-box;
}


/*
 * DWGrid Tools use a zero-height host and render upward from the Grid edge.
 *
 * When a page also has right-aligned page actions, reserve a dedicated
 * tools strip so the two control groups can never overlap.
 *
 * Usage:
 *     <div class="dw-grid-host dw-grid-host--with-tools">
 */
.dw-grid-host--with-tools {
    padding-top: 30px;
}


/*
 * If a Grid already owns its own border/radius, use a plain host.
 */
.dw-grid-host--plain {
    border: 0;
    background: transparent;
}


/* =========================================================
   PAGE HEADER
   ========================================================= */

.dw-layout-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;

    width: 100%;
    min-width: 0;

    margin-bottom: 8px;

    box-sizing: border-box;
}

.dw-layout-page-heading {
    min-width: 0;
}

.dw-layout-page-title {
    margin: 0;

    color: #2f3942;

    font-size: 15px;
    line-height: 22px;
    font-weight: 600;
}

.dw-layout-page-subtitle {
    margin-top: 2px;

    color: #7a858f;

    font-size: 11px;
    line-height: 16px;
}

.dw-layout-page-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;

    min-width: 0;
}


/* =========================================================
   TWO-GRID / MULTI-PANEL HELPERS
   ========================================================= */

.dw-layout-row--stretch {
    align-items: stretch;
}

.dw-layout-row--stretch > .dw-layout-col {
    display: flex;
}

.dw-layout-row--stretch > .dw-layout-col > .dw-layout-panel,
.dw-layout-row--stretch > .dw-layout-col > .dw-grid-host {
    flex: 1 1 auto;
}


/* =========================================================
   RESPONSIVE BEHAVIOUR
   ========================================================= */

@media (max-width: 1600px) {
    .dw-app-layout {
        width: calc(100% - 24px);
    }

    .dw-app-layout--left {
        margin-left: 12px;
    }
}

@media (max-width: 1100px) {
    .dw-layout-col--1-3,
    .dw-layout-col--2-3,
    .dw-layout-col--1-4,
    .dw-layout-col--3-4 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .dw-layout-row > .dw-layout-col {
        margin-bottom: var(--dw-layout-gap);
    }

    .dw-layout-row > .dw-layout-col:last-child {
        margin-bottom: 0;
    }
}

@media (max-width: 900px) {
    .dw-layout-grid-bar {
        align-items: flex-start;
        flex-direction: column;
        gap: 6px;
    }

    .dw-layout-grid-bar > .dw-grid-tools {
        width: 100%;
    }

    .dw-layout-grid-bar > .dw-grid-tools .dw-grid-tools-inner {
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}

@media (max-width: 800px) {
    .dw-layout-col--1-2 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .dw-layout-page-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .dw-layout-page-actions {
        width: 100%;
        justify-content: flex-start;
    }
}

@media (max-width: 767px) {
    .dw-app-layout,
    .dw-app-layout--left {
        width: calc(100% - 16px);
        max-width: none;

        margin-left: 8px;
        margin-right: 8px;
    }

    .dw-layout-panel-body {
        padding: 8px;
    }

    .dw-layout-panel--grid .dw-layout-panel-body {
        padding: 0;
    }
}
