/* Final responsive layer: content reflows; wide records scroll within their tables. */
@media screen {
  html { -webkit-text-size-adjust:100%; }
  *, *::before, *::after { box-sizing:border-box; }
  .app-shell { min-height:100vh; min-height:100dvh; min-width:0; }
  .enterprise-topbar, .enterprise-content, .app-footer { width:calc(100% - var(--sidebar-width, 272px)); min-width:0; }
  .enterprise-content > *, .portal-main > *, .auth-shell > *, .row > *,
  .portal-grid > *, .owner-grid > *, .pos-grid > * { min-width:0; }
  .panel, .card, .portal-card, .auth-card, .table-responsive { min-width:0; max-width:100%; }
  .table-responsive { overflow-x:auto; overscroll-behavior-x:contain; }
  .enterprise-content img, .portal-main img, .auth-shell img, video, canvas { max-width:100%; }
  .enterprise-content pre, .portal-main pre { max-width:100%; overflow:auto; }
  .global-search-trigger { min-width:0; }
  .page-header, .owner-card-header, .portal-list-item { flex-wrap:wrap; }
  .auth-footer-links { flex-wrap:wrap; }
  .auth-shell { min-height:100dvh; }
  .sidebar { height:100dvh; }
  .upos-ai-panel { height:calc(100dvh - 36px); max-height:calc(100dvh - 36px); }
  .upos-ai-message-body, .ai-message, .portal-ai-msg { overflow-wrap:anywhere; min-width:0; }
  .ai-assistant .ai-chat-panel { min-height:0; }
  .ai-assistant .ai-messages { height:clamp(160px, 38dvh, 440px); min-height:160px; flex:0 0 auto; overscroll-behavior-y:contain; }
  .ai-assistant .ai-conversations { max-height:min(40dvh, 360px); }
  .ai-disclosure > summary { cursor:pointer; font-weight:650; padding-block:8px; }
  .ai-disclosure > summary:focus-visible { outline:2px solid var(--color-primary, #2563eb); outline-offset:3px; }
  .ai-history[open] > summary { margin-bottom:8px; }
  .ai-chat-heading, .ai-chat-tools, .ai-answer-actions { display:flex; flex-wrap:wrap; gap:8px; min-width:0; }
  .ai-chat-tools > .btn, .ai-answer-actions > .btn { width:auto !important; min-height:44px; }
  .ai-assistant .ai-form .input-group { display:flex; flex-wrap:nowrap; min-width:0; gap:8px; }
  .ai-assistant .ai-form textarea.form-control { flex:1 1 0; width:0; min-width:0; min-height:70px; max-height:25dvh; resize:vertical; font-size:16px; }
  .ai-assistant .ai-form .btn { width:48px; flex:0 0 48px; border-radius:8px !important; }
}
@media screen and (max-width:1199.98px) {
  .ai-chat-column { order:1; }
  .ai-history-column { order:2; }
  .ai-assistant .ai-messages { height:clamp(160px, 30dvh, 360px); }
  .ai-assistant .ai-suggestions .btn { width:auto; text-align:left; white-space:normal; }
}
@media screen and (max-width:991.98px) {
  .enterprise-topbar, .enterprise-content, .app-footer,
  body.sidebar-collapsed .enterprise-topbar, body.sidebar-collapsed .enterprise-content,
  body.sidebar-collapsed .app-footer { margin-left:0; width:100%; }
  .enterprise-content { padding-inline:clamp(12px, 2.5vw, 24px); }
  .portal-topbar, .portal-hero { min-width:0; }
  .portal-brand { min-width:0; }
}
@media screen and (max-width:767.98px) {
  .enterprise-content, .portal-main { padding-inline:max(12px, env(safe-area-inset-left)); padding-right:max(12px, env(safe-area-inset-right)); }
  .ai-assistant .ai-chat-panel { padding:14px; }
  .ai-chat-heading > div:first-child { flex:1 1 100%; }
  .ai-chat-tools { width:100%; }
  .ai-assistant .ai-suggestions { display:grid; grid-template-columns:minmax(0,1fr); }
  .ai-assistant .ai-suggestions .btn { width:100%; min-height:44px; }
  .ai-assistant .ai-message { max-width:96%; }
  .ai-answer-actions { align-items:stretch; }
  .enterprise-content input:not([type=checkbox]):not([type=radio]),
  .enterprise-content select, .portal-main input, .portal-main select, .auth-shell input { max-width:100%; }
  .portal-bottom-nav { padding-bottom:env(safe-area-inset-bottom); }
}
@media screen and (max-width:575.98px) {
  .upos-ai-panel { inset:0; width:100%; height:100dvh; max-height:100dvh; }
  .upos-ai-composer { padding-bottom:max(12px, env(safe-area-inset-bottom)); }
  .portal-topbar { flex-wrap:wrap; }
}
@media screen and (max-height:500px) and (orientation:landscape) {
  .ai-assistant .ai-messages { height:160px; }
  .upos-ai-panel { top:0; bottom:0; height:100dvh; max-height:100dvh; }
}

/* Touch actions adapt to their container instead of retaining desktop widths. */
@media screen and (max-width:991.98px) {
  .enterprise-content .btn, .portal-main .btn, .auth-shell .btn {
    min-width:44px;
    max-width:100%;
    min-height:44px;
    height:auto;
    padding:10px 12px;
    line-height:1.3;
    white-space:normal;
    overflow-wrap:anywhere;
    text-align:center;
    flex-shrink:1;
    touch-action:manipulation;
  }
  .enterprise-content .btn > i, .portal-main .btn > i, .auth-shell .btn > i { flex:0 0 auto; }
  .enterprise-content .btn > span, .portal-main .btn > span { min-width:0; }
  .enterprise-content .d-flex.gap-1, .enterprise-content .d-flex.gap-2,
  .enterprise-content .d-flex.gap-3, .portal-main .d-flex.gap-2 { flex-wrap:wrap; }
  .enterprise-content .btn-group, .portal-main .btn-group {
    display:flex;
    flex-wrap:wrap;
    width:auto;
    max-width:100%;
    gap:6px;
  }
  .enterprise-content .btn-group > .btn, .portal-main .btn-group > .btn {
    flex:1 1 auto;
    width:auto;
    margin:0 !important;
    border-radius:6px !important;
  }
  .enterprise-content .panel > .d-flex .btn { width:auto; }
  .owner-header-actions { flex-wrap:wrap; gap:8px; }
  .workspace-action-bar { flex-wrap:wrap; overflow:visible; }
  .workspace-action-bar button, .workspace-action-bar a { min-height:44px; height:auto; max-width:100%; white-space:normal; }
}
@media screen and (max-width:767.98px) {
  .workspace-action-bar, .pos-command-bar {
    display:grid;
    grid-template-columns:repeat(auto-fit,minmax(min(130px,100%),1fr));
    gap:8px;
    max-width:100%;
    overflow:visible;
  }
  .workspace-action-bar button, .workspace-action-bar a,
  .pos-command-bar button, .pos-command-bar a {
    width:100%;
    min-width:0;
    height:auto;
    min-height:44px;
    padding:10px;
    white-space:normal;
    overflow-wrap:anywhere;
    justify-content:center;
  }
  .workspace-action-bar kbd, .workspace-checkout-actions kbd { display:none; }
  .workspace-checkout-actions { gap:8px; }
  .workspace-checkout-actions > .btn { flex:1 1 120px; }
  .workspace-checkout-actions > .btn-primary { flex-basis:100%; }
  .ai-chat-tools > .btn { flex:1 1 auto; }
}
@media screen and (max-width:575.98px) {
  .enterprise-content .page-header > .btn,
  .enterprise-content form.panel > .btn { width:100%; }
  .enterprise-content .d-flex.flex-wrap > .btn,
  .portal-main .d-flex.flex-wrap > .btn { flex:1 1 140px; }
  .enterprise-content .btn-group > .btn, .portal-main .btn-group > .btn { flex-basis:120px; }
}
