/*
  Layout primitives for the application shell. Smartphone-first: the shell is a single
  column with a top app bar by default; ≥768px it gains room for side navigation that the
  full BaseLayout-based MainLayout introduces in a later wave. Keep these rules structural;
  component-specific styling lives in CSS-isolation files.
*/

*,
*::before,
*::after {
    box-sizing: border-box;
}

.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    background-color: var(--color-bg-surface);
}

.app-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    background-color: var(--color-bg-elevated);
}

.app-main {
    flex: 1 1 auto;
    padding: var(--space-4);
}

@media (min-width: 768px) {
    .app-main {
        padding: var(--space-4) calc(var(--space-4) * 1.5);
    }
}

/*
  Between the compact breakpoint and the width a table actually needs, columns would be
  clipped rather than reachable — the surrounding page does not scroll horizontally. The
  wrapper carries the scrolling; above that range it is inert.
*/
.stacking-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 640px) {
    /* Rows are cards here, so nothing overflows and a scrollbar would only add noise. */
    .stacking-table-scroll {
        overflow-x: visible;
    }
}

/*
  Stacking tables.

  Below the compact breakpoint a data table cannot keep its columns: at 390px the customer
  grid measured 697px wide and was simply clipped — the trailing columns, including the row
  actions, were unreachable rather than merely cramped. Marking a table `.stacking-table`
  turns every row into a card and prefixes each cell with its column name.

  Contract for the markup: each `<td>` carries `data-label` with the same localized text as
  its `<th>`. A cell that is purely decorative or repeats the card heading can opt out with
  `data-label=""`. Cells holding only buttons should also carry `stacking-table-actions`,
  which lays them out as a row instead of a label/value pair.
*/
@media (max-width: 640px) {
    .stacking-table,
    .stacking-table tbody,
    .stacking-table tr,
    .stacking-table td {
        display: block;
        width: auto;
    }

    .stacking-table thead {
        display: none;
    }

    .stacking-table tr {
        margin-bottom: var(--space-3);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        background: var(--color-bg-surface);
        overflow: hidden;
    }

    .stacking-table td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: var(--space-3);
        padding: 10px 14px;
        border: none;
        border-bottom: 1px solid var(--color-border);
        text-align: left;
    }

    .stacking-table tr td:last-child {
        border-bottom: none;
    }

    .stacking-table td::before {
        content: attr(data-label);
        flex: 0 0 40%;
        min-width: 0;
        font-family: var(--font-display);
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--color-text-muted);
        overflow-wrap: anywhere;
    }

    /* Cells that opt out of the label column span the full card width. */
    .stacking-table td[data-label=""]::before {
        content: none;
    }

    .stacking-table td[data-label=""] {
        display: block;
    }

    /* The value side must be free to wrap; long names and e-mail addresses are the norm here. */
    .stacking-table td > * {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .stacking-table .stacking-table-actions {
        justify-content: flex-end;
        gap: var(--space-2);
        background: var(--color-bg-surface-alt);
    }

    .stacking-table .stacking-table-actions::before {
        flex: 1 1 auto;
    }
}
