/* Global responsive baseline for all app templates. */
:root {
    --bp-sm: 600px;
    --bp-md: 768px;
    --bp-lg: 1024px;
    --touch-target: 44px;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --page-inline: clamp(0.875rem, 2.8vw, 2rem);
}

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    min-width: 320px;
    min-height: 100vh;
    min-height: 100dvh;
    max-width: 100%;
    overflow-x: hidden;
    font-size: clamp(0.9375rem, 0.2vw + 0.9rem, 1rem);
    line-height: 1.5;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Fluid typography defaults that can still be overridden per page. */
h1 {
    font-size: clamp(1.5rem, 4.8vw, 2.75rem);
    line-height: 1.2;
}

h2 {
    font-size: clamp(1.25rem, 3.8vw, 2rem);
    line-height: 1.25;
}

h3 {
    font-size: clamp(1.125rem, 3.1vw, 1.5rem);
    line-height: 1.3;
}

/* Media should scale to container width by default. */
img,
video,
canvas,
iframe {
    max-width: 100%;
    height: auto;
}

svg {
    max-width: 100%;
}

iframe {
    width: 100%;
}

/* Prevent long words/URLs from forcing horizontal overflow. */
:where(p, li, a, span, td, th, h1, h2, h3, h4, h5, h6, code, pre) {
    overflow-wrap: anywhere;
}

/* Flex/Grid children should be allowed to shrink instead of overflowing. */
:where(
    .shell,
    .page-wrap,
    .page-content,
    .page,
    .center-block,
    .nav-links,
    .nav-actions,
    [class*="grid"],
    [class*="row"],
    [class*="col"]
) {
    min-width: 0;
}

/* Mobile-first spacing helpers for common app containers. */
:where(.page-content, .page, main) {
    max-width: 100%;
}

/* Touch-friendly controls (44px minimum recommended target size). */
:where(
    button,
    [role="button"],
    input[type="button"],
    input[type="submit"],
    input[type="reset"],
    .nav-link,
    .avatar-item,
    .btn,
    .copy-btn,
    .toggle-btn,
    .followup-btn,
    .tool-action,
    .lang-trigger,
    .nav-ham,
    .nav-toggle
) {
    min-height: var(--touch-target);
}

:where(.nav-ham, .nav-toggle, .user-avatar, .icon-btn) {
    min-width: var(--touch-target);
    min-height: var(--touch-target);
}

a,
button,
input,
select,
textarea {
    touch-action: manipulation;
}

input,
select,
textarea {
    max-width: 100%;
}

/* Keep default spacing usable on narrow screens. */
:where(.nav-links, .nav-actions, .btn-row, .actions, .controls, .tool-actions) {
    gap: var(--space-2);
}

/* Responsive table baseline.
   JS auto-wraps tables in .table-scroll on table-heavy routes. */
table {
    width: 100%;
    max-width: 100%;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-scroll > table {
    min-width: 640px;
}

/* Card-style table view on very small screens for selected pages. */
table.table-cards-mobile,
table.table-cards-mobile thead,
table.table-cards-mobile tbody,
table.table-cards-mobile tr,
table.table-cards-mobile th,
table.table-cards-mobile td {
    display: block;
    width: 100%;
}

table.table-cards-mobile thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

table.table-cards-mobile tr {
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 0.75rem;
    padding: 0.5rem;
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.01);
}

table.table-cards-mobile td {
    border: 0 !important;
    white-space: normal;
    text-align: left !important;
    padding: 0.45rem 0.25rem !important;
}

table.table-cards-mobile td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.6875rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.7;
    margin-bottom: 0.18rem;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Progressive enhancement breakpoints. */
@media (min-width: 600px) {
    :where(.nav-links, .nav-actions, .btn-row, .actions, .controls, .tool-actions) {
        gap: var(--space-3);
    }

    table.table-cards-mobile,
    table.table-cards-mobile thead,
    table.table-cards-mobile tbody,
    table.table-cards-mobile tr,
    table.table-cards-mobile th,
    table.table-cards-mobile td {
        display: revert;
    }

    table.table-cards-mobile tr {
        border: revert;
        margin-bottom: 0;
        padding: 0;
        border-radius: 0;
        background: transparent;
    }

    table.table-cards-mobile td::before {
        content: none;
    }
}

@media (min-width: 768px) {
    .table-scroll > table {
        min-width: 0;
    }
}
